0

I'm still sort of new to JavaScript and so I was playing around with some Javascript. I used let car = null; and had console.log(car) into the console which came up to null of course. I then console.log(typeof car) into the console this time but came back as an object. I was wondering why since I let car = null?

let car = null; console.log(car); //came back as null console.log(typeof car); //came back as object So I thought that would come back as null as well after I console.log(typeof car); but didn't and came back as an object.

Xay
  • 11
  • 1

2 Answers2

0

It's the behavior of this operator - check MDN Page

enter image description here

Kaashan
  • 352
  • 3
  • 12
-1

w3schools states the following

In JavaScript null is "nothing". It is supposed to be something that doesn't exist.

Unfortunately, in JavaScript, the data type of null is an object.

You can consider it a bug in JavaScript that typeof null is an object. It should be null.

Nsevens
  • 2,588
  • 1
  • 17
  • 34