GBG IDology
is now GBG

Accurate identity verification worldwide.

Learn more

Understanding Javascript The Weird Part Parts [patched] Instant

typeof null; // 'object' (bug in JS) typeof function(){}; // 'function' (but not a separate type) [] instanceof Array; // true [] instanceof Object; // true (arrays are objects) false , 0 , '' (empty string), null , undefined , NaN , -0 , 0n

function outer() let secret = 'closed over'; return function inner() console.log(secret); ; understanding javascript the weird part parts

function Dog(name) this.name = name; Dog.prototype.bark = function() return 'woof'; ; const d = new Dog('Rex'); d.bark(); // 'woof' Weird parts: typeof null; // 'object' (bug in JS) typeof

const obj = name: 'Alice', greet() console.log(this.name); ; const greetFn = obj.greet; greetFn(); // undefined (default binding, not implicit) Fix: use arrow functions (lexical this ) or .bind() . The weird part: A function “remembers” its lexical scope even when executed outside it. // true [] instanceof Object

typeof null; // 'object' (bug in JS) typeof function(){}; // 'function' (but not a separate type) [] instanceof Array; // true [] instanceof Object; // true (arrays are objects) false , 0 , '' (empty string), null , undefined , NaN , -0 , 0n

function outer() let secret = 'closed over'; return function inner() console.log(secret); ;

function Dog(name) this.name = name; Dog.prototype.bark = function() return 'woof'; ; const d = new Dog('Rex'); d.bark(); // 'woof' Weird parts:

const obj = name: 'Alice', greet() console.log(this.name); ; const greetFn = obj.greet; greetFn(); // undefined (default binding, not implicit) Fix: use arrow functions (lexical this ) or .bind() . The weird part: A function “remembers” its lexical scope even when executed outside it.