Understanding Javascript The Weird Part Parts (2026)
function Dog(name) this.name = name; Dog.prototype.bark = function() return 'woof'; ; const d = new Dog('Rex'); d.bark(); // 'woof' Weird parts:
| 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
getObj(); // undefined Place { on same line as return . 10. NaN – Not a Number Weird part: NaN is a number type, and it’s not equal to itself. function Dog(name) this
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. const obj = name: 'Alice', greet() console
0 == false // true '' == false // true null == undefined // true [] == '' // true (both become empty string) [] == 0 // true Always prefer === (no coercion), except when checking null == undefined . 7. Asynchronous Weirdness: Event Loop The weird part: JS is single-threaded but can handle async tasks.
function Dog(name) this.name = name; Dog.prototype.bark = function() return 'woof'; ; const d = new Dog('Rex'); d.bark(); // 'woof' Weird parts:
| 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 |
getObj(); // undefined Place { on same line as return . 10. NaN – Not a Number Weird part: NaN is a number type, and it’s not equal to itself.
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.
0 == false // true '' == false // true null == undefined // true [] == '' // true (both become empty string) [] == 0 // true Always prefer === (no coercion), except when checking null == undefined . 7. Asynchronous Weirdness: Event Loop The weird part: JS is single-threaded but can handle async tasks.