I've found many discussions about undefined as value e.g. how to check if is equal etc. But what is the "engineering" reason for the existence of the undefined as a global variable? There is no null variable in opposite...
console.log(undefined in this); // logs true
console.log(null in this); // logs false
In JavaScript, null
is a reserved word; undefined
isn't, but is implemented by the environment as a global variable with a value of undefined
.
You'll notice you can change the value of undefined
, but not of null
, except in strict mode (which will throw an error) or ES5 (which will ignore the assignment.)
Now, why undefined
is not reserved, I do not know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With