Java Script Fun and Curiosities
What some developers also know is NaN (not a number).
var variables; variable == undefined
undefined = "not defined"; var variables; variable == undefined
vara = 5; var b = "5"; a == b;
As a developer, however, it may also be desirable to carry out this comparison correctly. There is a little trick for that:
vara = 5; var b = "5"; a === b;
Another = is added to the comparison. This not only checks what is in the variable, but also whether their data type is actually the same. So you get False as the answer to the query, since 5 is somehow the text 5, but a number is not text.
This is due to machine accuracy. Unfortunately, this builds rounding errors into the calculation, so that the upper floating-point calculation has the following result: 0,30000000000000004.
But that is very easy to explain. In the background, the representation of true is a 1.
1 + "23" - 10
"2" + 1
But what happens in the following case?
"2" - 1
3> 2> 1
So if you sort the following list, then we all know what the result is, at least we hope:
[10, 1, 3].sort()
As we learned earlier, it would be too easy if the answer was [1, 3, 10]. No, the answer is [1, 10, 3]. But why is that now?
Finally, let's just make a banana out of a bacterium. How to do this is very simple: we string letters together to form the word bacteria and write it in lower case:
("b" + "a" ++"cteri" + "a").toLowerCase()
Yes, I did press the + twice, but that shouldn't be so bad.
But how could that happen?
What happens if we just don't write that in lower case?
("b" + "a" ++ "cteri" + "a")
Now the answer is “baNaNa”.