undefined and null

suggest change

At first glance it may appear that null and undefined are basically the same, however there are subtle but important differences.

undefined is the absence of a value in the compiler, because where it should be a value, there hasn’t been put one, like the case of an unassigned variable.

Setting a variable to undefined means the variable effectively does not exist. Some processes, such as JSON serialization, may strip undefined properties from objects. In contrast, null properties indicate will be preserved so you can explicitly convey the concept of an “empty” property.

The following evaluate to undefined:

undefined is also a property of the global window object.

// Only in browsers
console.log(window.undefined); // undefined
window.hasOwnProperty('undefined'); // true

Before ECMAScript 5 you could actually change the value of the window.undefined property to any other value potentially breaking everything.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Built-in constants:
* null
* undefined and null
* NaN

Table Of Contents
3 Built-in constants
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde