Difficulty rating is subjective, with a maximum of five stars and a minimum of one star.

A:

typeof null   // 'object'
Copy the code

Typeof operators operate on primitive data types:

typeof 'lin'      // 'string'
typeof NaN        // 'number'
typeof 1          // 'number'
typeof true       // 'boolean'
typeof undefined  // 'undefined'
typeof Symbol(a)// 'symbol'
typeof null       // 'object'
Copy the code

Why is null, a basic data type, recognized as object by the Typeof operator?

In fact, this is a bug left over from the first version of Javascript.

When typeOF is executed, ‘object’ will be returned. When typeof is executed, ‘object’ will be returned. When typeof is executed, ‘object’ will be returned.

So why did a bunch of design language gurus allow this bug to persist for so many years?

Because this bug involves so many Web systems, once it is changed, it will create more bugs and make many systems not work, and it may never be fixed.

To determine if a type is null, write:

let a = null
if (a === null) {
  // do something
}
Copy the code

or

let a = null
if(! a &&typeof a === 'object') {
  // do something
}
Copy the code

This is the 33rd day of alynn’s blog, delivering insight techniques. Goodbye

The last:

The “Front End of the Day question (4)” talks about the type conversion mechanism in JS

Next up:

What is the difference between “front-end daily question (6)” == and ===?