In any line that evaluates multiple conditions, JS does its best to short- circuit what needs to be evaluated.
Automatic Type Conversion (Via Type Coercion)
JS does its best to allow any types to be compared and returned. Its interpreter performs type coercion on the values it is “confused” about.
console.log(8 * null); // converts null to 0, returns 0 console.log("5" - 1); // converts "5" to 5, returns 4 console.log("5" + 1); // converts 1 to "1", returns "51" console.log("five" * 2);// cannot perform conversion on "five", returns NaN
Note that the type coercion being performed is heavily dependent on the operation; The values being evaluated and converted are secondary in comparison.
Variables & Data Binding
There are three keywords that represent assigning a value to a variable:
- var - allows for defining a global variable. When var is used in the context of a local block, the associated variable can be accessed outside said block.
- let - introduced in ES2015. Allows for defining a local variable whose scope is exactly the block it belongs to.
- const - when used in assignment, behaves like final in Java. The associated variables behave just like variables defined with let, only they cannot be modified at all in the future.