JS Test #10: null + undefined
source link: https://dev.to/coderslang/js-test-10-null-undefined-5f1p
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Test your JavaScript skills (10 Part Series)
What’s the difference between null
and undefined
in JavaScript? What will be logged to the console?
.
In the first line, we evaluate null === null
and the result is true
.
In the second line, we evaluate undefined === undefined
and the result is true
once again.
In the third line, however, we need to understand what the result of null + undefined
is. For JavaScript, it’s hard to make sense of what it should be, so it evaluates this expression as NaN
.
Now, is NaN
equal to NaN
?
And the answer is - NO.
In JS NaN
is the only value that’s not equal to itself.
ANSWER: The output is going to be true
, true
, and false
.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK