Understanding Javascript The Weird Part Parts !!top!! Direct

function getObj() return // ASI adds semicolon here → returns undefined ok: true ;

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: understanding javascript the weird part 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 |

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. function getObj() return // ASI adds semicolon here

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

'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. 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.