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
🌐
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 - If you create useRef with undefined, Typescript assumes that it’s a value container and returns type of MutableRefObject<T>. This doesn’t match the type that element’s ref property is expecting and throws error. Typescript returns RefObject<T> only if useRef is initialized with null. To find out more why it is designed this way, read this and this. So you cannot get away from null if you’re using Typescript and has to use useRef as an element reference. You cannot return undefined in your React component
🌐
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?

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript | MDN
Like undefined, accessing any property on null throws a TypeError instead of returning undefined or searching prototype chains.
🌐
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 .
🌐
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.
🌐
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 · That's it. Hope you learned something. If you spot any interesting bits or tweaks to be done on this post, let's discuss it here or reach out on twitter ... You're destructuring an object that you immediately create with the property 'a'. and in the case that 'a' doesn't exist, set the default to be 'Bob'
🌐
Scaler
scaler.com › topics › javascript › null-and-undefined-in-javascript
Null and Undefined in JavaScript - Scaler Topics
April 21, 2022 - Null in JavaScript means an empty value and is also a primitive type in JavaScript. The variable which has been assigned as null contains no value. Undefined, on the other hand, means the variable has been declared, but its value has not been assigned.
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › react-null-or-undefined-check
Check if a Variable is Null or Undefined in React | bobbyhadz
It checks for both null and undefined because when compared using loose equality null is equal to undefined.
🌐
Coding Beauty
codingbeautydev.com › home › posts › how to check if a variable is null or undefined in react
How to Check if a Variable is Null or Undefined in React
October 4, 2023 - If cartItems is undefined, it’ll mean that the shopping cart hasn’t been initialized yet, or an error occurred while fetching it, and we should load this data before proceeding. If cartItems is null, it’ll mean that the shopping cart is empty – the user hasn’t added any items yet. Here’s a simplified example of how you might handle this in a React component:
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
null and undefined are loosely equal, but not strictly equal. The loose equality operator coerces operands of different types to boolean values, making null and undefined both false.
🌐
Flexiple
flexiple.com › javascript › undefined-vs-null-javascript
Undefined vs Null - Javascript - Flexiple
Here as the variable is declared but not assigned to any value, the variable by default is assigned a value of undefined. On the other hand, null is an object. It can be assigned to a variable as a representation of no value. JavaScript never sets a value to null.
🌐
GitHub
github.com › facebook › react › issues › 7204
Any reason to use "null" instead of "undefined" for default state? Using default would allow using es6 default values · Issue #7204 · facebook/react
July 6, 2016 - facebook / react Public · Notifications · You must be signed in to change notification settings · Fork 50k · Star 241k · New issueCopy link · New issueCopy link · Closed · Closed · Any reason to use "null" instead of "undefined" for default state? Using default would allow using es6 default values#7204 ·
Published   Jul 06, 2016
🌐
Jser
jser.dev › react › 2022 › 02 › 04 › how-React-handles-empty-values
How does React handle empty values(null/undfined/Booleans) internally?
In updateSlot() and updateFromMap(), we find the similar pattern in which empty values are simply ignored and null is returned. ... That’s it. We now know how empty values are handled in React - the are simply ignored.
🌐
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.