Skip to content

Instantly share code, notes, and snippets.

@simplifyjs
Last active December 6, 2019 09:33
Show Gist options
  • Save simplifyjs/0720f60e59d3c50e76a15f9ab38e1f22 to your computer and use it in GitHub Desktop.
Save simplifyjs/0720f60e59d3c50e76a15f9ab38e1f22 to your computer and use it in GitHub Desktop.
Comparison and Tricky parts of null, undefined and NaN
if(undefined) // false
if(null) // false
if(NaN) // false
!undefined // true
!null // true
!NaN // true
+undefined // NaN
+null // 0
+NaN // NaN
-undefined // NaN
-null // -0
-NaN // -NaN
undefined == undefined // true
undefined == null // true
undefined == NaN // false
undefined === undefined // true
undefined === null // false because null is under object data type!
undefined === NaN // false
null == null // true
null == undefined // true
null == NaN // false
null === null // true
null === undefined // false = object === undefined
null === NaN // false
0 == undefined // false
0 == null // false
0 == NaN // false
undefined + undefined // NaN
undefined + null // NaN
undefined + null // NaN
null + null // 0
null + undefined // NaN
null + NaN // NaN
NaN + NaN // NaN
NaN + null // NaN
NaN + undefined // NaN
"123" + undefined // "123undefined"
"123" + null // "123null"
"123" + NaN // "123NaN"
123 + undefined // NaN
123 + null // 0
123 + NaN // NaN
true + undefined // NaN
true + null // 1
true + NaN // NaN
false + undefined // NaN
false + null // 0
false + NaN // NaN
parseInt(undefined) // NaN
parseInt(null) // NaN
parseInt(NaN) // NaN
Number(undefined) // NaN
Number(null) // 0
Number(NaN) // NaN
10 / null // Infinity, any number divided by null is equals to Infinity
-10 / null // -Infinity, any negative number divided by null is equals to -Infinity
var arr = [1,2,3];
arr[5] // undefined
delete arr[1];
arr[1] // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment