Maybe a little bit ;)
- To see some crazy examples of JS behaviour
- To laugh
- To understand the logic behind the scenes
[] == [] // false[] == ![] // true
The abstract equality operator converts both sides to numbers to compare them, and both sides become the number 0 for different reasons.
+[] == +![]0 == +false0 == 0true + true
// 2
When the plus operator is placed between two booleans, the booleans are converted to numbers
Number(true) + Number(true)1 + 1parseInt("f*ck"); // -> NaN
parseInt("f*ck", 16); // -> 15This happens because parseInt will continue parsing character-by-character until it hits a character it doesn't know. The 'f' in 'f*ck' is the hexadecimal digit 15. By default radix is 10 (decimal)
999999999999999 // -> 999999999999999
9999999999999999 // -> 1000000000000000010000000000000000;// -> 1000000000000000010000000000000000 + 1 // -> 1000000000000000010000000000000000 + 1.1 // -> 10000000000000002This is caused by IEEE 754-2008 standard for Binary Floating-Point Arithmetic. At this scale, it rounds to the nearest even number.
1 < 2 < 3 // true3 > 2 > 1 // false1 < 2 < 3 true < 3 1 < 3 // true3 > 2 > 1true > 11 > 1 // falseMath.min(1, 4, 7, 2); // 1
Math.max(1, 4, 7, 2); // 7Math.min() > Math.max(); // trueMath.min(); // Infinity
Math.max(); // -Infinitynull == 0; // falsenull > 0; // falsenull >= 0; // truenull == 0 // falseIf you have null on one side of the equal sign, the other side must be null or undefined for the expression to return true. Since this is not the case, false is returned.
null > 0 // falseThe algorithm here, unlike that of the abstract equality operator, will convert null to a number.
0 > 0 // falseThe >= operator in fact works in a very different way, which is basically to take the opposite of the < operator.
null >= 0!(null < 0)!(0 < 0)!(false)[] + {} // "[object Object]"{} + [] // 0From transposition of elements a sum does not change
Or does it?
{} + []+[] // 0[] + {}[].toString() + ({}).toString()'' + "[object Object]" // "[object Object]"{} parsed as empty block expresion
1 + {} // "1[object Object]"{} + 1 // 1('b' + 'a' + + 'tman').toUpperCase()// "BANAN"
('b' + 'a' + + 'tman').toUpperCase()('ba' + (+ 'tman')).toUpperCase()('ba' + NaN).toUpperCase()('ba' + 'NaN').toUpperCase() // BANANSkype: yavorco
Email: roman.yavoriv@techmagic.co