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
🌐
Beyondjava
beyondjava.net › null-vs-undefined
Null vs. undefined
Beyond Java · Sitemap · Talks & Articles · Projects · Guest Posts · About · Legalese · Statistics · (opt out) · Mastodon
🌐
Quora
quora.com › What-is-the-main-difference-between-NULL-and-UNDEFINED-in-programming-Are-they-both-non-existent-values
What is the main difference between 'NULL' and 'UNDEFINED' in programming? Are they both 'non-existent values'? - Quora
Answer (1 of 9): An undefined variable does not exist at all. This error usually occurs when you attempt to access a variable before it has even been created. On the other hand, a NULL variable exists, but holds a value of zero/nothing.
🌐
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
🌐
Quora
basicprogramming.quora.com › What-is-the-difference-between-NAN-NULL-and-UNDEFINED
What is the difference between NAN, NULL and UNDEFINED? - Basic Programming - Quora
Answer (1 of 6): * Null - Null represents an empty value and carry no meaningful information. * Undefined - Undefined represents any value that has not been defined anywhere in the program.
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
... You might define a variable ... also assign the null value to an existing reference to clear a previous value. undefined is a primitive ......
Find elsewhere
🌐
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
🌐
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.
🌐
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.
🌐
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?

🌐
Hacker News
news.ycombinator.com › item
Ask HN: Should scripting engines distinguish between "null" and "undefined"? | Hacker News
January 28, 2024 - Do scripting languages really need both "null" and "undefined" values · i have long liked that JavaScript provides both "null" and "undefined", and have modeled my scripting languages after that since tinkering with them first became a hobby (right at 20 years ago).
🌐
Scaler
scaler.com › topics › javascript › null-and-undefined-in-javascript
Null and Undefined in JavaScript - Scaler Topics
April 21, 2022 - Besides, when a function doesn't return a value, it returns undefined. ... In JavaScript, to check the type of variable, we use the "typeof" operator. ... As discussed above, the type of null is an object.
🌐
Coders Campus
coderscampus.com › home › ep37 – null vs undefined in javascript
EP37 - Null vs Undefined in JavaScript - Coders Campus
April 9, 2021 - One thing that threw me off when I started learning JavaScript (with a background in Java) was the fact that JavaScript has both undefined and null as possible values for a variable. In Java, all we have is just null which means that
🌐
HowToDoInJava
howtodoinjava.com › home › typescript › difference between undefined and null
JavaScript - Difference between undefined and null
September 22, 2021 - A variable is said to be “undefined” if it has been declared but not initialized. Whereas “null” is assigned to a variable whose value is absent.
🌐
TutorialsPoint
tutorialspoint.com › What-is-the-difference-between-null-and-undefined-in-JavaScript
What is the difference between null and undefined in JavaScript?
It means a variable declared, but no value has been assigned to the variable. JavaScript automatically assigns undefined to uninitialized variables. ... null is an intentional absence of a value. It is often used when a developer wants to indicate that a variable or object property has no value.
🌐
DEV Community
dev.to › nunocpnp › differences-between-null-and-undefined-keywords-2e2m
Differences between "null" and "undefined" keywords? - DEV Community
September 5, 2019 - They both represent a empty value. Difference nr 1! When you define a variable but not as... Tagged with javascript, webdev, todayilearned, beginners.
🌐
Reddit
reddit.com › r/javascript › null vs undefined
r/javascript on Reddit: null vs undefined
June 21, 2017 - Just adding on: Notice how when you initialize a variable, it is always automatically set to undefined at first? It's because it literally does not have a definition. Things that are null do have a definition. They are defined as void. ... Oh man the null thing I didn't know about. Which has led to me go read this whole SO question: https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript