Understanding Javascript The Weird Part Parts __full__ Page
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.
Here’s a structured guide to understanding the classic (and famously quirky) areas of JavaScript—often referred to as the “weird parts” made popular by Anthony Alicea’s course “JavaScript: Understanding the Weird Parts” . The weird part: You can use variables before they’re declared. understanding javascript the weird part parts
'5' - 1; // 4 (string to number) '5' + 1; // '51' (number to string) +'5'; // 5 (unary plus) !!'false'; // true (non-empty string) use Number() , String() , or explicit Boolean() . 9. Semicolon Insertion (ASI) Weird part: JS adds semicolons automatically, sometimes breaking code. const obj = name: 'Alice', greet() console
function outer() let secret = 'closed over'; return function inner() console.log(secret); ; The weird part: You can use variables before
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.