---
title: "The behaviour of typeof with null in JavaScript."  
description: "The behaviour of typeof with null in JavaScript."  
author: "Ashutosh Patel"  
published: 2024-12-23  
updated: 2024-12-30  
canonical: https://www.mindstick.com/forum/161076/the-behaviour-of-typeof-with-null-in-javascript  
category: "javascript"  
tags: ["javascript", "javascript object"]  
reading_time: 2 minutes  

---

# The behaviour of typeof with null in JavaScript.

[Understanding](https://www.mindstick.com/articles/12918/cat-5e-vs-cat-6a-understanding-the-major-differences) the behaviour of typeof with [null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp) in JavaScript.

## Replies

### Reply by Khushi Singh

**The** `typeof` **operator has unexpected behavior in JavaScript when it is applied to null. Specifically:**

```javascript
console.log(typeof null); // Outputs: "object"
```

**Why Does** `typeof null` **Return "object"?**\
That is, actually, a common feature in JavaScript that most developers know. Looking back to the very beginning of JavaScript, starting with dealing with the first syntax, the values were represented as type tags in bits. The type tag for objects was 0, and null lay fallow for a time and was given this type tag so it existed as an “object.” Ironically, this behavior was never fixed for the sake of backward compatibility.

**Practical Implications**\
Confusion for Beginners: The opinion on the nature of typeof null That is why many developers expect typeof null to return ‘null’ instead of ‘object’.\
Type Checking: If you wish to look for null in the data specifically then you should use strict equality operators

```javascript
if (value === null) {
  console.log("Value is null");
}
```

For beginners learning JavaScript, understanding quirks like these is crucial. If you're just starting your JavaScript journey, our guide on [How to Learn JavaScript Faster](https://www.mindstick.com/articles/279873/learn-javascript-faster-tips-and-advice-for-beginners) provides valuable tips.


---

Original Source: https://www.mindstick.com/forum/161076/the-behaviour-of-typeof-with-null-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
