undefined means a variable has been declared but has not yet been assigned a value :

var testVar;
console.log(testVar); //shows undefined
console.log(typeof testVar); //shows undefined

null is an assignment value. It can be assigned to a variable as a representation of no value :

var testVar = null;
console.log(testVar); //shows null
console.log(typeof testVar); //shows object

From the preceding examples, it is clear that undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.

Proof :

console.log(null === undefined) // false (not the same type)
console.log(null == undefined) // true (but the "same value")
console.log(null === null) // true (both type and value are the same)

and

null = 'value' // Uncaught SyntaxError: invalid assignment left-hand side
undefined = 'value' // 'value'
Answer from sebastian on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › undefined-vs-null-in-javascript
Undefined Vs Null in JavaScript - GeeksforGeeks
July 23, 2025 - undefined indicates a variable hasn’t been initialized, while null is intentionally assigned to indicate no value. Understanding the distinction helps write cleaner, more predictable code in JavaScript, especially when handling default values or checking for missing data.
Discussions

Undefined vs null
Hello. What is the difference between undefined and null? More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
November 19, 2019
null vs undefined
I try to think of it simply as: undefined means exactly that, we have not bothered to set a value for this thing. null means we explicitly set a value and wanted it to be anomalous. null shows intentionality you cannot infer from undefined. More on reddit.com
🌐 r/javascript
43
132
June 21, 2017
JavaScript undefined vs. null

:)

ya, i know.. glad someone passed on the wisdom.

the way i always keep it in mind is to just consider the fact that both null and undefined are more falsish than they are trueish..

i know, all the hardcore C heads are going to scream "NULL IS UNKNOWN ITS NOT TRUE OR FALSE!"

but that doesn't matter.

what you are thinking as a normal human, and not a machine. Null is closer to the idea of a non-thing than it is to a thing. Therefor whenever you just want to know if something exists or has value you can say:

if (thing) alert(thing);

but, be careful when your var is a number, because 0 will fail this test too. the simplest way to keep all this strait is to just keep your numeric primitives sep from your objects.

More on reddit.com
🌐 r/programming
4
0
February 14, 2005
Not sure when to use Undefined and Null in JavaScript?

When the typeof keyword is used on undefined it outputs "undefined" which is correct. When typeof is used on null it outputs "object "which is not correct and is a flaw in the language that was never fixed. Therefore it is a perfectly acceptable practice to simply never use null and always use undefined. You can use null if you want to but there is no reason to. Here is a reference: https://www.youtube.com/watch?v=vJKDh4UEXhw&feature=youtu.be&t=38m60s

More on reddit.com
🌐 r/learnjavascript
5
2
September 29, 2014
🌐
Reddit
reddit.com › r/typescript › undefined vs null
r/typescript on Reddit: Undefined vs null
February 27, 2023 -

Since switching to TypeScript I have been using a lot of optional properties, for example:

type store = {
  currentUserId?: string
}

function logout () {
  store.currentUserId = undefined
}

However my coworkers and I have been discussing whether null is a more appropriate type instead of undefined, like this:

type store = {
  currentUserId: string | null
}

function logout () {
  store.currentUserId = null
}

It seems like the use of undefined in TypeScript differs slightly from in Javascript.

Do you guys/girls use undefined or null more often? And, which of the examples above do you think is better?

🌐
DEV Community
dev.to › sduduzog › null-vs-undefined-what-to-choose-what-to-use-11g
null vs undefined? What to choose? What to use? - DEV Community
August 23, 2023 - When a javascript object is being serialized, all undefined properties are discarded, remember 'undefined' means a property is yet to be assigned a value. But null on the other hand is known by JSON as its a valid JSON data type
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
You can also assign the null value ... value. undefined is a primitive value assigned to variables that have just been declared, or to the resulting value of an operation that doesn't return a meaningful value....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript | MDN
October 28, 2025 - The keyword null is a literal for the null value. Unlike undefined, which is a global variable, null is not an identifier but a syntax keyword.
🌐
CoreUI
coreui.io › blog › what-is-the-difference-between-null-and-undefined-in-javascript
What is the Difference Between Null and Undefined in JavaScript · CoreUI
February 9, 2025 - According to the typeof operator, however, typeof null returns 'object'—a quirk dating back to the original JavaScript implementation. If you see null console outputs it indicates a deliberate decision to assign null. This is different from a variable that is simply undefined.
Find elsewhere
🌐
Syncfusion
syncfusion.com › blogs › post › null-vs-undefined-in-javascript
Null vs. Undefined in JavaScript | Syncfusion Blogs
December 10, 2024 - Some of the significant differences between null and undefined are: JavaScript always assigns undefined to indicate the absence of a value by default, and it never automatically assigns null as a value.
🌐
Hacker News
news.ycombinator.com › item
The difference between null and undefined in JavaScript is something I wished ha... | Hacker News
October 13, 2021 - I have only seen null vs undefined lead to 2 things in my experience: mistakes and bikeshedding · The "billon dollar mistake" as described by Tony Hoare was not nulls per se
🌐
Medium
medium.com › weekly-webtips › null-and-undefined-in-javascript-d9bc18acdaff
Null and Undefined in Javascript
February 17, 2021 - Interesting thing about null is that null expresses the lack of identification, meaning the variable points to no object. A variable that has not been assigned a value is considered a type of undefined .
🌐
CodeParrot
codeparrot.ai › blogs › javascript-null-vs-undefined-key-differences-when-to-use-each
JavaScript Null vs Undefined: Key Differences & When to Use Each
November 8, 2024 - In JavaScript, both null and undefined indicate "no value," but they serve different roles. When compared using loose equality (==), JavaScript considers null and undefined to be loosely equal, as they both imply an absence.
🌐
Scaler
scaler.com › topics › javascript › null-and-undefined-in-javascript
Null and Undefined in JavaScript - Scaler Topics
April 4, 2024 - Unlike null, the value of an undefined variable is set by JavaScript as undefined. The variable gets created at the run-time. When we do not pass an argument for a function parameter, the default value is taken as undefined.
🌐
CodeBurst
codeburst.io › javascript-whats-the-difference-between-null-undefined-37793b5bfce6
JavaScript — What’s the difference between Null & Undefined? | by Brandon Morelli | codeburst
July 5, 2017 - null is also an object. Interestingly, this was actually an error in the original JavaScript implementation: ... Undefined means a variable has been declared, but the value of that variable has not yet been defined.
🌐
CodingNomads
codingnomads.com › null-undefined-difference-javascript
Null vs Undefined: Understanding the Differences in JavaScript
Unlike undefined, null has to be set by the developer explicitly. null represents an empty value; the variable has a value and that value is null, which signals an intent to communicate that it has "no value".
🌐
Web Dev Simplified
blog.webdevsimplified.com › 2021-01 › null-vs-undefined
Null Vs Undefined
January 11, 2021 - Both null and undefined mean that there is no value. If a variable is set to null or undefined it has no value and if a function returns null or undefined then it is saying it has no value to return.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Undefined vs null - JavaScript - The freeCodeCamp Forum
November 19, 2019 - Hello. What is the difference between undefined and null?
🌐
Medium
medium.com › @o_o_o › null-vs-undefined-can-i-use-only-one-a3b7db5468f2
null vs. undefined: Can I use only one? | by OOO | Medium
March 29, 2022 - It is even considered as design mistake by JavaScript’s creator, Brendan Eich. So I wanted to simplify things by having only one non-value. The biggest downside of only using null is that undefined is everywhere.
🌐
CodeBurst
codeburst.io › understanding-null-undefined-and-nan-b603cb74b44c
Understanding null, undefined and NaN. | by Kuba Michalski | codeburst
November 12, 2018 - When you declare a variable but don’t declare its value, JavaScript assigns “undefined” value to it. If you try any arithmetic operations with undefined, you are going to get NaN(you can just trust me with this one or check it out on your own 🙃). Similar as with null, negating undefined gives true, but comparing it to either true or false gives false.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Comparisons
3 weeks ago - Comparisons convert null to a number, treating it as 0. That’s why (3) null >= 0 is true and (1) null > 0 is false. On the other hand, the equality check == for undefined and null is defined such that, without any conversions, they equal each other and don’t equal anything else.