(name is undefined)

You: What is name? (*)
JavaScript: name? What's a name? I don't know what you're talking about. You haven't ever mentioned any name before. Are you seeing some other scripting language on the (client-)side?

name = null;

You: What is name?
JavaScript: I don't know.

In short; undefined is where no notion of the thing exists; it has no type, and it's never been referenced before in that scope; null is where the thing is known to exist, but it's not known what the value is.

One thing to remember is that null is not, conceptually, the same as false or "" or such, even if they equate after type casting, i.e.

name = false;

You: What is name?
JavaScript: Boolean false.

name = '';

You: What is name?
JavaScript: Empty string


*: name in this context is meant as a variable which has never been defined. It could be any undefined variable, however, name is a property of just about any HTML form element. It goes way, way back and was instituted well before id. It is useful because ids must be unique but names do not have to be.

Answer from Rob on Stack Overflow
Top answer
1 of 16
1532
(name is undefined)

You: What is name? (*)
JavaScript: name? What's a name? I don't know what you're talking about. You haven't ever mentioned any name before. Are you seeing some other scripting language on the (client-)side?

name = null;

You: What is name?
JavaScript: I don't know.

In short; undefined is where no notion of the thing exists; it has no type, and it's never been referenced before in that scope; null is where the thing is known to exist, but it's not known what the value is.

One thing to remember is that null is not, conceptually, the same as false or "" or such, even if they equate after type casting, i.e.

name = false;

You: What is name?
JavaScript: Boolean false.

name = '';

You: What is name?
JavaScript: Empty string


*: name in this context is meant as a variable which has never been defined. It could be any undefined variable, however, name is a property of just about any HTML form element. It goes way, way back and was instituted well before id. It is useful because ids must be unique but names do not have to be.

2 of 16
147

The difference can be summarized into this snippet:

alert(typeof(null));      // object
alert(typeof(undefined)); // undefined

alert(null !== undefined) //true
alert(null == undefined)  //true

Checking

object == null is different to check if ( !object ).

The latter is equal to ! Boolean(object), because the unary ! operator automatically cast the right operand into a Boolean.

Since Boolean(null) equals false then !false === true.

So if your object is not null, but false or 0 or "", the check will pass because:

alert(Boolean(null)) //false
alert(Boolean(0))    //false
alert(Boolean(""))   //false
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript | MDN
JavaScript is unique to have two nullish values: null and undefined. Semantically, their difference is very minor: undefined represents the absence of a value, while null represents the absence of an object. For example, the end of the prototype chain is null because the prototype chain is ...
🌐
Reddit
reddit.com › r/learnjavascript › "typeof" null an object?
r/learnjavascript on Reddit: "typeof" null an object?
November 26, 2022 -

We know that the "typeof" null in javascript is an object, and we also know that it's a bug in JavaScript. I wanted to know what kind of bug it is, and why anyone hasn't resolved it yet.

🌐
Quora
quora.com › Why-is-null-considered-an-object-in-JavaScript
Why is null considered an object in JavaScript? - Quora
Answer: ‘Null’ is a basic building block in JavaScript thus why it is referred to as a primitive data type and provides built-in support. Other primitive data type include strings, numbers, booleans, null and undefined. Then, there are object data types(or non-primitive data types).
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-null
Everything about null in JavaScript
null in JavaScript is a special value that represents a missing object.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › null-in-javascript
Null in JavaScript - GeeksforGeeks
June 5, 2024 - In JavaScript, `null` indicates the deliberate absence of any object value. It's a primitive value that denotes the absence of a value or serves as a placeholder for an object that isn't present.
🌐
DEV Community
dev.to › _ravo_lution › why-typeof-null-is-object-181
Why typeof(null) is "object"? - DEV Community
July 26, 2021 - Or it was zero, then the type tag was three bits in length, providing two additional bits, for four types. ... null (JSVAL_NULL) was the machine code NULL pointer. Or: an object type tag plus a reference that is zero. **Let's look at the classic JavaScript Source code used in the '96 in SpiderMonkey courtesy: @evilpies: https://twitter.com/evilpies/
🌐
2ality
2ality.com › 2013 › 10 › typeof-null.html
The history of “typeof null”
Update 2013-11-05: I take a look at the C code of typeof to better explain why typeof null results in 'object'. In JavaScript, typeof null is 'object', which incorrectly suggests that null is an object (it isn’t, it’s a primitive value, consult my blog post on categorizing values for details).
Find elsewhere
🌐
GitHub
github.com › rohan-paul › Awesome-JavaScript-Interviews › blob › master › Javascript › Tricky-JS-Problems › typeof-null-why-its-object.md
Awesome-JavaScript-Interviews/Javascript/Tricky-JS-Problems/typeof-null-why-its-object.md at master · rohan-paul/Awesome-JavaScript-Interviews
In fact, the ECMAScript specification defines null as the primitive value that represents the intentional absence of any object value (ECMA-262, 11.4.11). To draw a parallel here, consider typeof(NaN) === "number". So why does JavaScript give "number" as the type of NaN (not a number)? It is because NaN is used where numbers appear, it is a value that represents the intentional absence of a number value.
Author   rohan-paul
🌐
Medium
mike-diaz006.medium.com › what-i-learned-at-work-this-week-is-null-an-object-491203650b83
What I Learned at Work this Week: Is null an object? | by Mike Diaz | Medium
May 8, 2021 - None of the types listed, including undefined, allow for a variable to be defined as null (AnalyticsData is a custom interface, but it’s an object with a bunch of optional properties). It’s smart to recognize that the original logic wouldn’t have worked if target was null, but for some reason it’s still allowed despite this setting. This wasn’t exactly the most complex problem to solve, but it’s always exciting when we can learn something new about a language and apply what we know to fix a bug. If you love JavaScript like me, then you love it as it is.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Errors › No_non-null_object
TypeError: "x" is not a non-null object - JavaScript | MDN
The JavaScript exception "is not a non-null object" occurs when an object is expected somewhere and wasn't provided. null is not an object and won't work.
🌐
Rollbar
rollbar.com › home › how to fix typeerror: null is not an object in javascript
How to Fix TypeError: Null is Not an Object in JavaScript | Rollbar
September 28, 2022 - The TypeError: null is not an object occurs when a property is read (or set) or a method is called on a null value. An object was expected in code but was not provided. Since null is not an object in JavaScript, using a null value when an object ...
🌐
Medium
medium.com › @kaustavxg › why-typeof-null-is-object-in-javascript-e1c205d05c77
Why typeof null is 'object' in JavaScript | by Kaustav Gupta | Medium
June 14, 2025 - So when the JavaScript engine evaluated typeof null, it interpreted the tag as "object", because it had no way of distinguishing null from an object using just those few bits. Nope.
🌐
Flexiple
flexiple.com › javascript › undefined-vs-null-javascript
Undefined vs Null - Javascript - Flexiple
However, there were no pointers ... 0’s. Hence all its 32 bits were 0’s. So whenever the JavaScrit interpreter reads null, it considers the first 3 bits as type “object”. That is why typeof null returns “objec...
🌐
Sololearn
sololearn.com › en › Discuss › 3314273 › why-does-typeof-null-show-object-in-javascript
Why does typeof null show 'object' in JavaScript? | Sololearn: Learn to code for FREE!
... It is actually a historical bug from days of old when javascript was first assigning the typeof to data types and null was assigned as an object. The original creators chose not to " fix it " verses saying undefined or NAN.
🌐
JavaScript Tutorial
javascripttutorial.net › home › an essential guide to javascript null
An Essential Guide to JavaScript null
September 29, 2020 - JavaScript uses the null value to represent a missing object. Use the strict equality operator (===) to check if a value is null. The typeof null returns 'object', which is historical bug in JavaScript that may never be fixed.
🌐
Sololearn
sololearn.com › en › Discuss › 1751310 › why-type-of-null-is-object
Why type of null is object?? | Sololearn: Learn to code for FREE!
null is a primitive type in JavaScript but typeof null returns object, this is a bug in JavaScript language which existed from first version of JavaScript.
🌐
Mohit Singh Chauhan
mohitdotexe.hashnode.dev › is-javascript-null-actually-a-object
Is JavaScript Null actually a Object ?
August 10, 2023 - The typeof null behavior is one such example! In the first version of JavaScript, there were only five primitive data types: ... That was it! No other primitive types like null, symbol, or bigint existed. So at that time, the typeof operator only needed to distinguish between these five types. To actually understand why null returns "object", we need to learn how values are represented in memory in JavaScript.