EN
JavaScript - why is null an object and what's the difference between null and undefined?
1
answers
0
points
Why is null an object type and what's the difference between null and undefined?
When I'm checking:
if ( object == null ) {
// some action...
}
it's the same as:
if (!object) {
// some action...
}
also:
console.log(typeof null === 'object'); // true
1 answer
0
points
1. undefined is a primitive value automatically assigned to variables that have just been declared. It is where no notion of the variable exists, it has no type and it's never been referenced before in that scope,
2. null represents the intentional absence of any object value (e.g the variable is known to exist but it is not known what the value is).
Note:
nullis not the same asfalseor""values, even if it's treated as falsy for boolean operations:// ONLINE-RUNNER:browser; console.log(false == ''); // true console.log(false == null); // false console.log('' == null); // false
References
0 comments
Add comment