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 == +false
0 == 0
true + true
// 2
When the plus operator is placed between two booleans, the booleans are converted to numbers
Number(true) + Number(true)
1 + 1
parseInt("f*ck"); // -> NaN
parseInt("f*ck", 16); // -> 15
This 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 // -> 10000000000000000
10000000000000000;// -> 10000000000000000
10000000000000000 + 1 // -> 10000000000000000
10000000000000000 + 1.1 // -> 10000000000000002
This 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 // true
3 > 2 > 1 // false
1 < 2 < 3
true < 3
1 < 3 // true
3 > 2 > 1
true > 1
1 > 1 // false
Math.min(1, 4, 7, 2); // 1
Math.max(1, 4, 7, 2); // 7
Math.min() > Math.max(); // true
Math.min(); // Infinity
Math.max(); // -Infinity
null == 0; // false
null > 0; // false
null >= 0; // true
null == 0 // false
If 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 // false
The algorithm here, unlike that of the abstract equality operator, will convert null to a number.
0 > 0 // false
The >= 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]"
{} + [] // 0
From 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() // BANAN
Skype: yavorco
Email: roman.yavoriv@techmagic.co