Cannot intercept direct access to properties in JavaScript. When a property is restored that has not been set, the result will be undefined . Although null and undefined are usually considered the same, they are actually different objects.
In JavaScript, undefined does not have a value, and null means null. In some cases, you can mix undefined and null. For example, when using the == operator, they are equivalent ( (null == undefined) === true ). Using the operator without coercion, === , they are different ( (null === undefined) === false ).
You can take advantage of this. While most people claim that you should use the force equality operator ( === ), itβs basically safe to put null and undefined in the same bucket, especially since you really care about the difference between the two, Where it becomes it is difficult that undefined is a property of a global object and therefore a new value can be assigned.
If someone says undefined = 'donkey' , then null == undefined will start returning false . In practice, this is almost never a problem, since most people are not stupid enough to reassign an undefined value.
This way you do not need to intercept access to properties to return null for properties that were not set while you compare the result with null with == ./p>
source share