Understanding Javascript The Weird Part Parts Best -
In an arrow function, this is lexically bound, meaning it inherits this from its surrounding code.
| Concept | Golden Rule | |-----------------------|-------------| | Hoisting | Declarations are moved up, not initializations | | this | Depends on call site, not definition | | Closure | Function + its outer scope | | Prototypes | Objects delegate to other objects | | == vs === | Use === unless you need coercion | | Async order | Sync → Microtasks → Macrotasks | | Type coercion | Explicit > implicit | | Semicolons | Don’t rely on ASI for critical cases |
const greetFunction = person.greet; greetFunction(); // "Hello, undefined" (this = global object) understanding javascript the weird part parts
The == vs === battle. Double equals ( == ) performs type coercion, leading to the infamous "WAT" moments in JavaScript.
JS adds semicolons automatically, sometimes breaking code. In an arrow function, this is lexically bound,
'5' - 1; // 4 (string to number) '5' + 1; // '51' (number to string) +'5'; // 5 (unary plus) !!'false'; // true (non-empty string)
Where the actual lines of code you wrote reside. Name Property: (Optional) The name of the function. JS adds semicolons automatically, sometimes breaking code
Never use floating-point math for financial calculations directly. Multiply your numbers to whole integers, do the math, and then divide back, or use libraries designed for precision.
Dog.prototype = Object.create(Animal.prototype); Dog.prototype.constructor = Dog;