use let
when creating variables for the first time
use const
to declare a constant (unlike all caps in ruby) - can't redefine/replace value of constant in JS
lowerCamelCase i.e. iPhone
increment a value:
let x = 5;
x++;
#x is now 6
Methods that accept code: in JavaScript, these are called “anonymous functions” rather than “blocks”.
If the method provides values for block variables, in Ruby we name them within optional “pipes” | |
after the do
. In JavaScript, we name them within the parentheses ( )
(which are not optional) after function
.
JS comparisons use triple ===
, not double ==
.
Beware: There’s also a JS double ==
(non-strict equivalence) operator. In most cases, you should use ===
.
jQuery()
alias $()
for shorthand
In JavaScript, you have to execute the function explicitly by adding the parentheses, even if there are no arguments. ie chi.text()
not chi.text
Any CSS property/value pair can be set with the css()
function.
Event handlers with on()
$("body").on("click", "#bye", function() {
$(".west").slideToggle();
});
This is saying: “Within , find elements with an id of
bye
, and when they are clicked run the following callback.” Now, whenever the div is clicked, elements with class west
will slide up and down.