Historical mistake in JavaScript | typeof null is 'object'?

Опубликовано: 08 Май 2024
на канале: Mayank Srivastava
346
15

when we compare the null and undefined primitive values by using the loose equality or abstract equality operator we get the result as true but when we compare them by using the strict equality operator we get the result as false. This behavior is due to the fact that js also compares the types of the operands along with their value while performing strict equality. while the typeof undefined is simply undefined, the typeof null is actually 'object'. This is the part where people might scratch their heads as to why the primitive value null has its type as object. Well, it's a historical quirk in JavaScript! Back in the early days of JavaScript, the language used a 32-bit value representation system. values were represented as a type tag and a value. the type bit pattern of null coincided with the object type pattern of object, both being zeros and because of it typeof null returns "object". But this does not change the fact that null is not an object. It's a primitive value representing the absence of any object value.


На этой странице сайта вы можете посмотреть видео онлайн Historical mistake in JavaScript | typeof null is 'object'? длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Mayank Srivastava 08 Май 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 346 раз и оно понравилось 15 зрителям. Приятного просмотра!