The Weird Side of JavaScript Explained - ...

The Weird Side of JavaScript Explained - Part 2

Jan 29, 2024

image

1. Arrays Are Not Equal

Despite having identical elements, two distinct arrays are not considered equal in JavaScript: imageThe reason is the same as above: == and === compare object references for arrays, and these two arrays are different objects in memory.

2. NaN Is a Number

NaN, which stands for "Not a Number," is ironically classified as a number:

imageNaN is a special numeric value that indicates that a result cannot be represented as a number. It’s the only value in JavaScript that is not equal to itself.

3. Arrays and Objects

When you try to add arrays or objects, you can get some strange results due to type coercion:imageThe plus operator triggers the default conversion to strings for both arrays and objects, leading to these odd outcomes.

4. Boolean Maths

Even booleans aren't safe from JavaScript’s quirks:imageIn arithmetic operations, true is converted to 1 and false to 0. Therefore, `

Part 1: https://www.buymeacoffee.com/codecrumbs/the-weird-side-javascript-explained-part-1

Original post: https://www.instagram.com/p/C1KUenOsCU9/?utm_source=ig_web_copy_link&igsh=MzRlODBiNWFlZA==

Подобається цей допис?

Купити для Codecrumbs каву

Більше від Codecrumbs