Before ES6 (ECMAScript 2015), we only had var . var behaves differently than let and const in two major ways: and hoisting .
| Binding Rule | Example | this value | |-------------------|----------------------------------|----------------------------| | Default | fn() | window (strict: undefined ) | | Implicit (object) | obj.fn() | obj | | Explicit | fn.call(obj) , fn.apply(obj) | obj | | new binding | new Fn() | new instance | understanding javascript the weird part parts
Fix: use arrow functions (lexical this ) or .bind() . Before ES6 (ECMAScript 2015), we only had var
function Animal(name) this.name = name;
typeof NaN; // 'number' NaN === NaN; // false isNaN('hello'); // true (coerces to NaN) Number.isNaN('hello'); // false (recommended) Before ES6 (ECMAScript 2015)