-2

I tried to run this code.

var is_null = null;
console.log(typeof is_null);

why 'is_null' is showing me Object when i watched in in the Console. How Null can be an Object. is Null an object in Javascript? please tell me if its a bug or it has some history behind it.

Null is not an object in any language. then why Null is an Object or shown as Object (in console) in JavaScript?

rameezmeans
  • 830
  • 1
  • 10
  • 21

1 Answers1

0

Guys I saw something here.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof

In the first implementation of JavaScript, JavaScript values were represented as a type tag and a value. The type tag for objects was 0. null was represented as the NULL pointer (0x00 in most platforms). Consequently, null had 0 as type tag, hence the bogus typeof return value. (reference)

A fix was proposed for ECMAScript (via an opt-in), but was rejected. It would have resulted in typeof null === 'null'.

// This stands since the beginning of JavaScript
typeof null === 'object';

can someone please explain this? because i did not get it entirely.

rameezmeans
  • 830
  • 1
  • 10
  • 21