A little bit too much of ES5 for an experienced developer.
- Symbol (new in ES2015)
- Object (Function, Array, Date, RegExp)
There are no integers in JS.
In practice, integer values are treated as 32-bit ints, and some implementations even store it that way until they are asked to perform an instruction that's valid on a Number but not on a 32-bit integer. This can be important for bit-wise operations.
Converting String to number: parseInt (use usually 10 as a second argument) or parseFloat. Or you can also use the unary + operator to convert values to numbers: + "10". Nice.
- NaN (check with isNaN)
- Infinity or -Infinity (isFinite)
More accurately, they are sequences of UTF-16 code units; each code unit is represented by a 16-bit number. Each Unicode character is represented by either 1 or 2 code units.
No more fun knowledge this time.
- false, 0, empty strings (""), NaN, null, and undefined all become false.
- All other values become true.
let allows you to declare block-level variables. The declared variable is available from the function block it is enclosed in. My name was featured in the article <3
const allows you to declare variables whose values are never intended to change. The variable is available from the function block it is declared in.
const Pi = 3.14; // variable Pi is set
Pi = 1; // will throw an error because you cannot change a constant variable.
If you add a string to a number (or other value) everything is converted in to a string first. This might catch you up:
- do .. while
- for(let value of array)
- for(let property in object)
Remember — the length of the array is one more than the highest index.