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
Undefined vs null
One reason to favor undefined over null is how javascript handle default values: const withDefault = (a = true) => { console.log(a); }; withDefault(); // logs true withDefault(undefined); // logs true withDefault(null); // logs null More on reddit.com
🌐 r/typescript
51
46
February 27, 2023
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
'null' or 'undefined': What should I use if I want to clear the variable from the memory?
As NateDzMtz says, the memory considerations are the same. null and undefined are unique values and don't involve any references into the heap. In this regard, false would have the same effect. As far as which is convenient for programming, since indexing an object with a key that is not found in the object returns undefined, storing undefined as the value almost simulates absence of the key. Of course, a query can be made to distinguish the case that foo has no key bar from the case where it has the key bar but undefined is stored as the value at that key. But if your design is such that those cases don't have different meanings, it's convenient to stifle slots by putting undefined in them. Note that delete can be inefficient in some engines and they are not required by the standard to make it efficient. I think that the conventional meanings of the special values are, more or less: undefined -- maybe was never initialized; isn't associated to any particular data type. null -- no object, where an object might be expected. NaN -- no number, where a number might be expected. false -- just not true, no other meaning. Note that typeof null is "object", even though you can't index null. typeof undefined is "undefined". typeof NaN is "number", even though NaN explicitly and exactly means "Not a Number"! More on reddit.com
🌐 r/learnjavascript
9
4
June 7, 2023
🌐
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 .
🌐
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.
🌐
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.
🌐
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.
🌐
GitBook
basarat.gitbook.io › typescript › recap › null-undefined
Null vs. Undefined | TypeScript Deep Dive
August 18, 2020 - Something hasn't been initialized : undefined. Something is currently unavailable: null. Fact is you will need to deal with both. Interestingly in JavaScript with ==, null and undefined are only equal to each other:
🌐
CodeBurst
codeburst.io › understanding-null-undefined-and-nan-b603cb74b44c
Understanding null, undefined and NaN. | by Kuba Michalski | codeburst
November 12, 2018 - Even though it points to something non existing, nothing, it’s a global object (and one of JavaScript’s primitive values). Negating null value returns true , but comparing it to false (or either true) gives false. In basic maths operations, null value is converted to 0. The global undefined property represents the primitive value undefined.