The == operator uses the Abstract Equality Comparison Algorithm , which coerces values to match before comparing them. This is why 0 == false and "" == false both return true .
The this keyword behaves differently in different contexts:
Everything else is truthy. Even:
Put { on the same line as return .
Just use === . Always. You don't want to debug this at 2 AM.
console.log(0.1 + 0.2); // 0.30000000000000004 console.log(0.1 + 0.2 === 0.3); // false
obj.printName();
const obj = { name: "John", printName: function() { console.log(this.name); } };
The this keyword in JavaScript can be confusing, especially when used in different contexts.
JavaScript has a concept called hoisting, which can lead to unexpected behavior if not understood properly. javascript weird parts
The arguments object in JavaScript functions can be confusing.
('b' + 'a' + + 'a' + 'a').toLowerCase() // "banana" // The + + 'a' tries to convert 'a' to a number, resulting in NaN. Use code with caution. Learn more about Type Coercion on Medium. 2. Execution Context and Hoisting
These values are considered falsy:
JavaScript is a versatile and widely-used programming language, but it also has some quirks and unexpected behaviors that can catch developers off guard. In this paper, we'll explore some of the weird parts of JavaScript and discuss how to navigate them.
Use a small epsilon or multiply by powers of 10 for money calculations (or use BigInt for integers).