JS… wszyscy wiemy jak zbudowany jest ten język i ile jest w nim dziwnych i nielogicznych rzeczy. Postaram się opisać i wytłumaczyć choć część porąbanych rzeczy jakich możemy uświadczyć w JSie.
"3" - 2
"3" + 2
[] + {}
[].toString() + {}.toString()
"" + "[object Object]"
"[object Object]"
{} + []
+ []
0
[1, 2, 3] + [4, 5, 6]
[1, 2, 3].toString() + [4, 5, 6].toString()
"1,2,3" + "4,5,6"
"1,2,34,5,6"
""*""
""**""
Number.MIN_VALUE > 0
Number.MIN_VALUE // -> 5e-324 (5 * 10^-324)
parseInt("foo")
parseInt("foo", 16)
parseInt("Infinity")
parseInt("Infinity", 19)
parseInt("Infinity", 24) // -> 151176378
parseInt("Infinity", 29) // -> 385849803
parseInt("Infinity", 36) // -> 1461559270678
parseInt("Infinity", 37) // -> NaN
null > 0
null > 0
null > 0
+null > +0
0 > 0
false
null > 0 null == 0
null == 0
null == 0
+null == +0
0 == 0
true
// it should be like this right?
null == 0
null > 0
null == 0
null >= 0
null >= 0
null >= 0
!(null < 0)
!(+null < +0)
!(0 < 0)
!false
true
1337 === 1337
NaN === NaN
NaN === NaN
1. If Type(x) is different from Type(y), return false.
2. If Type(x) is Number, then
a. If x is NaN, return false.
b. If y is NaN, return false.
[] == []
[] == ![]
[] == !true
[] == false
+[] == +false
0 == 0
true
[] == ""
[].toString() == ""
"" == ""
true
[0] == 0
[0].toString() == 0
"0" == 0
+"0" == 0
0 === 0
true
[[[[[[]]]]]] == 0
[[[[[[].toString()]]]]] == 0
[[[[[""].toString()]]]] == 0
[[[[""].toString()]]] == 0
[[[""].toString()]] == 0
[[""].toString()] == 0
[[""].toString()] == 0
[""].toString() == 0
"" == 0
+"" == 0
0 == 0
true
![] === ![]
!true === !true
false === false
true
["a","b","c"][3,2,1]
["a","b","c"][(3,2,1)]
["a","b","c"][1]
"b"
["1", "2", "3"].map(parseInt)
["1", "2", "3"].map((...args) => parseInt(...args))
["1", "2", "3"].map((val, i) => parseInt(val, i))
// [0] parseInt("1", 0) -> 1
// [1] parseInt("2", 1) -> NaN
// [2] parseInt("3", 2) -> NaN
[10, 9, 8, 3, 2, 1, 0].sort()
"[]\\`".match(/[A-z]/g)
function foo() {
return
{
bar: "hi"
};
}
function foo() {
return;
{
bar: "hi"
};
}
if (a == 0 && a == 1 && a == 2) {
console.log("Hi!");
}
const a = {
i: 0,
toString: function() {
return this.i++;
}
}