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
🌐
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
Discussions

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
Undefined vs null
Hello. What is the difference between undefined and null? More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
November 19, 2019
Falsy values vs null, undefined, or empty string
I've worked with jQuery over the years. However, recently, I've found myself getting deeper into the JavaScript language. Recently, I've heard about "truthy" and falsey values. However, I don't fully More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
arithmetic on NULL pointer -is it undefined behaviour?

The arithmetic itself is not undefined here. Look up how NULL is defined.

Edit: I stand corrected (see below)

More on reddit.com
🌐 r/C_Programming
64
19
August 7, 2019
🌐
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 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.
🌐
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 - Since undefined is the default value assigned by JavaScript to uninitialized variables, if you want to indicate the absence of a deal explicitly, always use null instead of undefined to avoid confusion. To check if a variable has any value before proceeding further in a program, you can use the loose equality ==null to check for either null or undefined.For example, in the following program, the function assignVal() checks whether the num is undefined or null and assigns the value given by the user only if the variable num is not initialized to any value.
Find elsewhere
🌐
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.
🌐
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.
🌐
W3Schools
w3schools.com › typescript › typescript_null.php
TypeScript Null & Undefined
When strictNullChecks is enabled, TypeScript requires values to be set unless undefined is explicitly added to the type. Optional chaining is a JavaScript feature that works well with TypeScript's null handling.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Data types
July 9, 2024 - In JavaScript, null is not a “reference to a non-existing object” or a “null pointer” like in some other languages. It’s just a special value which represents “nothing”, “empty” or “value unknown”. The code above states that age is unknown. The special value undefined also stands apart.
🌐
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 - When you assign null, you are specifying that no meaningful value exists at the moment, but the variable has been declared so it can hold future data. Also, note that unlike null, undefined usually arises without explicit action from the developer.
🌐
Sentry
sentry.io › sentry answers › javascript › undefined versus null in javascript
Undefined versus null in JavaScript | Sentry
October 21, 2022 - null and undefined are considered the same when using loose equality (==) but not when using strict equality (===).
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › everyday-types.html
TypeScript: Documentation - Everyday Types
JavaScript has two primitive values used to signal absent or uninitialized value: null and undefined.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Undefined vs null
November 19, 2019 - Hello. What is the difference between undefined and null?
🌐
CodeBurst
codeburst.io › understanding-null-undefined-and-nan-b603cb74b44c
Understanding null, undefined and NaN. | by Kuba Michalski | codeburst
November 12, 2018 - In basic maths operations, null value is converted to 0. The global undefined property represents the primitive value undefined. It is one of JavaScript's primitive types (source: MDN). It basically tells us that something isn’t defined. You get this e.g.
🌐
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 - null vs. undefined: Can I use only one? I tried it on my React app Why do you wanna use only one in the first place? null and undefined are used interchangeably to represent non-value. Why can’t I …
🌐
DEV Community
dev.to › icncsx › js-explain-undefined-null-and-nan-2lka
JS / explain undefined, null, and NaN - DEV Community
May 28, 2020 - Unlike undefined, null is never assumed by default. Null is typically used when we want to reset a variable; this is typically more clear than reassigning a variable to an empty string, 0, or undefined.
Top answer
1 of 5
24

In programming, truthiness or falsiness is that quality of those boolean expressions which don't resolve to an actual boolean value, but which nevertheless get interpreted as a boolean result.

In the case of C, any expression that evaluates to zero is interpreted to be false. In Javascript, the expression value in

if(value) {
}

will evaluate to true if value is not:

null
undefined
NaN
empty string ("")
0
false

See Also
Is there a standard function to check for null, undefined, or blank variables in JavaScript?

2 of 5
9

The set of "truthy" and "falsey" values in JavaScript comes from the ToBoolean abstract operation defined in the ECMAScript spec, which is used when coercing a value to a boolean:

+--------------------------------------------------------------------------+
| Argument Type | Result                                                   |
|---------------+----------------------------------------------------------|
| Undefined     | false                                                    |
|---------------+----------------------------------------------------------|
| Null          | false                                                    |
|---------------+----------------------------------------------------------|
| Boolean       | The result equals the input argument (no conversion).    |
|---------------+----------------------------------------------------------|
| Number        | The result is false if the argument is +0, −0, or NaN;   |
|               | otherwise the result is true.                            |
|---------------+----------------------------------------------------------|
| String        | The result is false if the argument is the empty String  |
|               | (its length is zero); otherwise the result is true.      |
|---------------+----------------------------------------------------------|
| Object        | true                                                     |
+--------------------------------------------------------------------------+

From this table, we can see that null and undefined are both coerced to false in a boolean context. However, your fields.length === 0 does not map generally onto a false value. If fields.length is a string, then it will be treated as false (because a zero-length string is false), but if it is an object (including an array) it will coerce to true.

If fields should be a string, then !fields is a sufficient predicate. If fields is an array, your best check might be:

if (!fields || fields.length === 0)
🌐
Vue.js
vuejs.org › guide › components › props
Props | Vue.js
defineProps({ // Basic type check // (`null` and `undefined` values will allow any type) propA: Number, // Multiple possible types propB: [String, Number], // Required string propC: { type: String, required: true }, // Required but nullable string propD: { type: [String, null], required: true }, // Number with a default value propE: { type: Number, default: 100 }, // Object with a default value propF: { type: Object, // Object or array defaults must be returned from // a factory function.
🌐
TypeScript
typescriptlang.org › docs › handbook › advanced-types.html
TypeScript: Documentation - Advanced Types
By default, the type checker considers null and undefined assignable to anything. Effectively, null and undefined are valid values of every type. That means it’s not possible to stop them from being assigned to any type, even when you would like to prevent it.