Javacript
Reserved Words
Numbers
- Positive / Negative
- NaN is a number but is not avalue - isNaN()
Strings
- string literal can be between '' or ""
- escape character \
- Print to console - ''Hello World''
- Tab = \t
- Carriage Return = \r
- New line = \n
Strings cont...
- length property
- Concatenation
Variables
- var name = 1; // int / number
- var name2 = 'hi!'; // string
Type Conversion
console.log(8 * null)
// → 0
console.log("5" - 1)
// → 4
console.log("5" + 1)
// → 51
console.log("five" * 2)
// → NaN
console.log(false == 0)
// → true
Operators
- operators for arithmetic (+, -, *, /, and %)
- string concatenation (+)
- comparison (==, !=, ===, !==, <, >, <=, >=)
- logic (&&, ||)
Unary Operators
- - to negate a number
- ! to negate logically
- typeof to find a value’s type
Conditionals
Controlling the flow of execution
If / Else
if (true){ } else { }
Else if
if (true){ } else if { } else {}
Do While
do{} while()
Execute body once
For loop
for(var i =0; i < 100; i++) { }
break
for(var i =0; i < 100; i++) { break; }
switch
switch(){ case "red": break; default: break; }
Functions
DRY - Dont repeat yourself
Creating Functions
function name() {} //moved to top
var name = function() {}
Nested Scope
- inner can see outer
- outer cannot see inner
Arrow functions
- name = x => { do stuff }
- shorthand