+ 3

Null

Why null data type of object in JavaScript?

14th Apr 2025, 3:41 PM
🌹Rose🌹
🌹Rose🌹 - avatar
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)
14th Apr 2025, 3:58 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar