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 - It means null is equal to undefined but not identical. When we define a variable to undefined then we are trying to convey that the variable does not exist .
๐ŸŒ
Web Dev Simplified
blog.webdevsimplified.com โ€บ 2021-01 โ€บ null-vs-undefined
Null Vs Undefined
The reason you would want to do this is to essentially reset a variable. By setting a variable to undefined you are conveying the message that the variable no longer contains any useful information, while if the value is null then you are ...
๐ŸŒ
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 - In contrast, null means a developer has explicitly assigned an empty value. The value null signals the intentional absence of data or object value. According to the typeof operator, however, typeof null returns 'object'โ€”a quirk dating back ...
๐ŸŒ
web.dev
web.dev โ€บ learn โ€บ javascript โ€บ data-types โ€บ null-undefined
null and undefined | web.dev
You might define a variable as null with the expectation that it reflects either a value assigned to it at some point in a script or an explicitly absent value. You can also assign the null value to an existing reference to clear a previous 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
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.
๐ŸŒ
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 - Ones that I can think from the top of my head is, they're both falsy values. This means that if you have a Boolean expression like if (null || undefined) you'll always get false from it.
๐ŸŒ
SheCodes
shecodes.io โ€บ athena โ€บ 2227-what-is-the-difference-between-null-and-undefined-in-javascript
[JavaScript] - What is the Difference Between Null and Undefined in JavaScript?
Learn what is the difference between null and undefined in JavaScript and how to distinguish between them. Check how to use a typeof operator.
Find elsewhere
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ javascript โ€บ null-and-undefined-in-javascript
Null and Undefined in JavaScript - Scaler Topics
April 21, 2022 - As the name suggests, undefined means "not defined". So we declare a variable but do not assign a value to it, the variable becomes undefined. Unlike null, the value of an undefined variable is set by JavaScript as undefined. The variable gets created at the run-time.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ javascript โ€บ undefined versus null in javascript
Undefined versus null in JavaScript | Sentry
null and undefined are considered the same when using loose equality (==) but not when using strict equality (===).
๐ŸŒ
Net Informations
net-informations.com โ€บ js โ€บ iq โ€บ nuvsun.htm
Null and Undefined in JavaScript
JacaScript undefined indicates the lack of an assigned value or the non-existence of a property, while null signifies an intentional absence of value.
๐ŸŒ
Flexiple
flexiple.com โ€บ javascript โ€บ undefined-vs-null-javascript
Undefined vs Null - Javascript - Flexiple
Many times we often get confused on what the difference between UNDEFINED and NULL is. Simply put, undefined means a variable has been declared but has not yet been assigned a value. undefined is a type by itself (undefined).
๐ŸŒ
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?

๐ŸŒ
Syncfusion
syncfusion.com โ€บ blogs โ€บ post โ€บ null-vs-undefined-in-javascript
Null vs. Undefined in JavaScript | Syncfusion Blogs
December 10, 2024 - Even though there are fundamental ... often tend to use them interchangeably due to the following similarities: Both denote the absence of a value....
๐ŸŒ
CodeBurst
codeburst.io โ€บ javascript-null-vs-undefined-20f955215a2
JavaScript โ€” Null vs. Undefined
January 16, 2018 - Hereโ€™s an example. We assign the value of null to a: ... Undefined most typically means a variable has been declared, but not defined.
๐ŸŒ
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 - Although React doc says โ€œfalse, ... throws following error: Nothing was returned from render. This usually means a return statement is missing....
๐ŸŒ
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 .
๐ŸŒ
Javatpoint
javatpoint.com โ€บ null-vs-undefined
Difference Between Null and Undefined - javatpoint
Difference Between Null and Undefined with typescript tutorial, typescript introduction, versions, typescript and javascript, features, components, installation, typescript types, etc.