I don't really have an answer, but according to Nicholas C. Zakas, page 30 of his book "Professional JavaScript for Web Developers":

When defining a variable that is meant to later hold an object, it is advisable to initialize the variable to null as opposed to anything else. That way, you can explicitly check for the value null to determine if the variable has been filled with an object reference at a later time

Answer from bbg on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript - MDN Web Docs
The null keyword refers to the null primitive value, which represents the intentional absence of any object value.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › null-in-javascript
Null in JavaScript - GeeksforGeeks
June 5, 2024 - In JavaScript, `null` indicates the deliberate absence of any object value. It's a primitive value that denotes the absence of a value or serves as a placeholder for an object that isn't present.
Discussions

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
133
January 13, 2018
Why does "typeof null" returns "object" instead of "null"? Is this a bug in the ECMA?
This was a bug in one of the very early versions of JavaScript IIRC. I believe it was added to the standard later once people started using it that way. If it makes you feel better the base prototype of all objects is null at the end of the chain. More on reddit.com
🌐 r/javascript
24
1
June 23, 2018
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Null
Null - Glossary - MDN Web Docs
In computer science, a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. The meaning of a null reference varies among language implementations. In JavaScript, null is marked as one of the primitive values, because its behavior ...
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
March 31, 2024 - 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.
🌐
Programiz
programiz.com › javascript › null-undefined
JavaScript null and undefined
Note: Usually, null is used to assign 'unknown' or 'empty' value to a variable. Hence, you can assign null to a variable. In JavaScript, null is a special value that represents an empty or unknown value.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › null
`null` in JavaScript - Mastering JS
December 2, 2020 - In JavaScript, null is a value that represents the intentional absence of any object value. It is technically a primitive type, although in some cases it behaves as an object.
🌐
JavaScript Tutorial
javascripttutorial.net › home › an essential guide to javascript null
An Essential Guide to JavaScript null
September 29, 2020 - To check if a value is not null, you use the strict inequality operator (!==): value !== nullCode language: JavaScript (javascript) JavaScript null has the following features. Besides false, 0, an empty string (''), undefined, NaN, null is a falsy value. It means that JavaScript will coerce null to false in conditionals.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › null
null - JavaScript | MDN
May 23, 2022 - The null keyword refers to the null primitive value, which represents the intentional absence of any object value.
Top answer
1 of 16
131

I don't really have an answer, but according to Nicholas C. Zakas, page 30 of his book "Professional JavaScript for Web Developers":

When defining a variable that is meant to later hold an object, it is advisable to initialize the variable to null as opposed to anything else. That way, you can explicitly check for the value null to determine if the variable has been filled with an object reference at a later time

2 of 16
121

At the end of the day, because both null and undefined coerce to the same value (Boolean(undefined) === false && Boolean(null) === false), you can technically use either to get the job done. However, there is right way, IMO.

  1. Leave the usage of undefined to the JavaScript compiler.

    undefined is used to describe variables that do not point to a reference. It is something that the JS compiler will take care for you. At compile time the JS engine will set the value of all hoisted variables to undefined. As the engine steps through the code and values becomes available the engine will assign respective values to respective variables. For those variables for whom it did not find values, the variables would continue to maintain a reference to the primitive undefined.

  2. Only use null if you explicitly want to denote the value of a variable as having "no value".

    As @com2gz states: null is used to define something programmatically empty. undefined is meant to say that the reference is not existing. A null value has a defined reference to "nothing". If you are calling a non-existing property of an object, then you will get undefined. If I would make that property intentionally empty, then it must be null so you know that it's on purpose.

TLDR; Don't use the undefined primitive. It's a value that the JS compiler will automatically set for you when you declare variables without assignment or if you try to access properties of objects for which there is no reference. On the other hand, use null if and only if you intentionally want a variable to have "no value".


Sidebar: I, personally, avoid explicitly setting anything to undefined (and I haven't come across such a pattern in the many codebases/third party libs I've interacted with). Also, I rarely use null. The only times I use null is when I want to denote the value of an argument to a function as having no value, i.e.,:

Copyfunction printArguments(a,b) {
  console.log(a,b);
}

printArguments(null, " hello") // logs: null hello
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
In JavaScript, null represents an intentional absence of a value, indicating that a variable has been declared with a null value on purpose. On the other hand, undefined represents the absence of any object value that is unintentional.
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-null
Everything about null in JavaScript - Dmitri Pavlutin
September 21, 2020 - null in JavaScript is a special value that represents a missing object.
🌐
Frank M Taylor
blog.frankmtaylor.com › 2023 › 05 › 25 › why-does-javascript-have-null-and-undefined
Why does JavaScript have null AND undefined? – Frank M Taylor
November 24, 2025 - All are objects. so I think Brendan ... everything is an object, JavaScript’s null actually has a more specific meaning of “no object”....
🌐
Tamalweb
tamalweb.com › null-javascript
What is null in JavaScript? | TamalWeb by Tamal Chowdhury
March 19, 2020 - What is null in JavaScript? null means no-value. When there is no value assigned to an object variable, it means the object doesn’t exist.
🌐
MDN Web Docs
devdoc.net › web › developer.mozilla.org › en-US › docs › JavaScript › Reference › Global_Objects › null.html
null - JavaScript | MDN
The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values.
🌐
SheCodes
shecodes.io › athena › 445562-what-is-null-in-javascript
[JavaScript] - What is null in JavaScript? - SheCodes | SheCodes
Learn about the special value 'null' in JavaScript and its use as a placeholder or to indicate the absence of a value in a variable.
🌐
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 . When we define a variable to null then we are trying to convey that the variable is empty. undefined indicates a variable hasn’t been initialized, while null is intentionally assigned to indicate no value...
🌐
Medium
medium.com › @stephenthecurt › a-brief-history-of-null-and-undefined-in-javascript-c283caab662e
A brief history of Null and Undefined in JavaScript | by Steve C | Medium
January 13, 2018 - Just like numbers and characters, ... is `null`. Same with `undefined`. These are used in JavaScript to act as placeholders to let the programmer know when a variable has no value....
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-null-and-undefined
Difference between null and undefined in JavaScript
Here you will learn what is null and undefined in JavaScript and what is the difference between them. A null means the absence of a value. You assign a null to a variable with the intention that currently this variable does not have any value ...
🌐
To The New
tothenew.com › home › difference between ‘null’ and ‘undefined’ in javascript
Difference Between ‘null’ and ‘undefined’ in JavaScript | TO THE NEW Blog
May 23, 2013 - An illustration of this assignment ... ... ‘Null’ is an object with a valid value, no properties, is non-mutable, and only a single instance of the same exists in the system at all times....