+ 3
Null
Why null data type of object in JavaScript?
1 Odpowiedź
+ 7
null is useful to check if an object exists/has been created
consider:
const obj = null
console.log(obj.name); // Error could crash our program
Fix
// if object exists
if (obj != null)
log(obj.name)
// otherwise move on
Shorter
log(obj?.name); // Problem: something will ALWAYS be printed (null or the actual name)