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
🌐
DEV Community
dev.to › nashmeyah › undefined-vs-null-vs-undeclared-9f8
Undefined vs. Null vs. Undeclared - DEV Community
March 29, 2021 - (MDN Web Docs, Online). Null means that the value is absent, not 0... the value points to no object. ... "The undefined property indicates that a variable has not been assigned a value, or not declared at all.", (W3Schools, Online).
🌐
DEV Community
dev.to › anewman15 › in-javascript-whats-the-difference-between-a-variable-that-is-null-undefined-and-undeclared-j1f
In JavaScript, what's the difference between a variable that is: null, undefined and undeclared? - DEV Community
July 24, 2022 - In JavaScript, it is common to declare and initialize a variable at the same time. It is also commonplace to declare a variable, leave it uninitialized, and then assign it at a later point. Any undeclared variable evaluated in the code, throws ReferenceError. null and undefined are JS primitives and they differ from each other in terms of their types and what values they represent.
🌐
Sentry
sentry.io › sentry answers › javascript › undefined versus null in javascript
Undefined versus null in JavaScript | Sentry
console.log(undeclaredVar); // will throw a ReferenceError console.log(typeof undeclaredVar); // will print "undefined" In contrast, null is a value that represents nothing. Think of null as an empty container and undefined as the absence of ...
🌐
GreatFrontEnd
greatfrontend.com › questions › quiz › whats-the-difference-between-a-variable-that-is-null-undefined-or-undeclared-how-would-you-go-about-checking-for-any-of-these-states
What's the difference between a JavaScript variable that is: `null`, `undefined` or undeclared? | Quiz Interview Questions with Solutions
September 5, 2021 - If a function does not return a value, and its result is assigned to a variable, that variable will also have the value undefined. To check for it, compare using the strict equality (===) operator or typeof which will give the 'undefined' string. Note that you should not be using the loose equality operator (==) to check, as it will also return true if the value is null.
🌐
Medium
rlynjb.medium.com › js-interview-question-what-s-the-difference-between-a-variable-that-is-null-undefined-or-bf7233cef1c2
JS Interview Question: What’s the difference between a variable that is: null, undefined or undeclared? | by RLyn Ben | Medium
January 3, 2021 - We use ‘console.log();’ and ‘type of’ to check if a variable is undefined or null. ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures · undeclared variables is a variable that has been declared without ‘var’ keyword. testVar = ‘hello world’; as opposed to var testVar = ‘hello world’; When former code is executed, undeclared variables are created as global variable and they are configurable (ex.
🌐
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 - However, undefined in JavaScript indicates the absence of an assigned value, while null means an empty value intentionally set by the developer. Recognizing this distinction helps prevent errors and clarifies the inner workings of your code.
🌐
Lucybain
lucybain.com › blog › 2014 › null-undefined-undeclared
Lucy | JS: null, undefined, and undeclared
You can know if a variable is undefined with the following: Finally we'll finish up with null. null is a variable that is defined to have a null value. You probably don’t often purposefully define a variable to null, but it may be the return value of a function. Often you'll need to gaurd against null values in your code. You can know if a variable is null with the following: I think the order “undeclared, undefined, and null” makes sense since it’s increasing order of certainty.
🌐
Sophiali
sophiali.dev › javascript-undeclared-undefined-null
Understanding undeclared, undefined, and null in JavaScript
if (undefined) { console.log('inside the true block') } else { console.log('undefined is falsy') } // undefined is falsy · null is one of JavaScript's primitive types. The value null is used for purposefully setting something to empty, the absence of a value.
Find elsewhere
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › type › undeclared, undefined and null
What's the difference between undeclared, undefined and null in JavaScript? - 30 seconds of code
June 12, 2021 - Accessing an undeclared variable will throw a ReferenceError. console.log(x); // ReferenceError: x is not defined · A variable is undefined if it hasn't been assigned a value. undefined is a primitive data type in JavaScript and represents ...
Top answer
1 of 3
2

At least in the time of writing... No, it does not seem that you can do something like this:

var a = undeclared(var) ? 'undeclared' : 'undefined'

The reason is that you cannot pass an undeclared variable to a function; It raises an error, even in non-strict mode.

The best we can do, is this:

var barIsDeclared = true;

try { bar; }
catch (e) {
  if (e.name == "ReferenceError") {
    barIsDeclared = false;
  }
}

console.log(barIsDeclared);

Why?

Undefined: It occurs when a variable has been declared but has not been assigned with any value. Undefined is not a keyword.

Undeclared: It occurs when we try to access any variable that is not initialized or declared earlier using var or const keyword. If we use ‘typeof’ operator to get the value of an undeclared variable, we will face the runtime error with return value as “undefined”. The scope of the undeclared variables is always global.

For example:

  • Undefined:
var a;
undefined
console.log(a) // Success!
  • Undeclared:
console.log(myVariable) // ReferenceError: myVariable is not defined

When we try to log an undeclared variable, it raises an error. Trying to log an undefined variable does not. We make a try catch to check for just that.

'use strict'

Worth mentioning that adding 'use strict' in your code verifies that no undeclared variable is present, and raises an error if one is present.

function define() {
 //'use strict' verifies that no undeclared variable is present in our code     
 'use strict';     
 x = "Defined";  
}

define();

ReferenceError: x is not defined

Further reading:

  • Checking if a variable exists in javascript
  • What are undeclared and undefined variables in JavaScript?
  • JS Interview Question: What’s the difference between a variable that is: null, undefined or undeclared?
  • JavaScript check if variable exists (is defined/initialized)
  • Strict mode
2 of 3
1

As others already did point to, the OP might want to distinguish between declared but undefined references and undeclared reference names ...

let declaredButUnassignedAndStrictlyEqualToUndefinedValue;
const declaredAndHavingAssignedTheUndefinedValue = undefined;

// There is no way of telling the above two (un/)assignements appart.

console.log(
  '(declaredButUnassignedAndStrictlyEqualToUndefinedValue === declaredAndHavingAssignedTheUndefinedValue) ?',
  (declaredButUnassignedAndStrictlyEqualToUndefinedValue === declaredAndHavingAssignedTheUndefinedValue)
);


// the `typeof` operator is of no help
// if it comes to distinguish between
// declared but undefined references
// and undeclared reference names ...

console.log(
  'typeof notDeclaredWithinScope :', typeof notDeclaredWithinScope
);

// ... just a try catch can do that.

try {
  notDeclaredWithinScope;
} catch (err) {
  // console.log(err.message);

  console.log('`notDeclaredWithinScope` does not exist within this scope.')
}
.as-console-wrapper { min-height: 100%!important; top: 0; }
🌐
ExplainThis
explainthis.io › en › swe › js-undefined-null-undeclared
What is the difference between null, undefined and undeclared in JavaScript?|ExplainThis
undefined means that it has been declared as a defined value, but undeclared means that it has never been declared. When a variable has not been declared using var, let or const, it is called undeclared.
🌐
Quora
candd.quora.com › Whats-the-difference-between-a-variable-that-is-null-undefined-or-undeclared-in-javascript
What's the difference between a variable that is: null, undefined or undeclared in javascript? - Daily Coding & Development - Quora
Answer (1 of 3): Undeclared: If a variable is not declared with its keyword like var / let / const then it is undeclared variable. console.log (a); //a is not defined Undefined: A variable is declared but its value is not assigned then it is ...
🌐
TechBrij
techbrij.com › javascript-null-undefined-undeclared
JavaScript: Null vs Undefined vs Undeclared - TechBrij
In modern browsers (which supports javascript 1.8.5), undefined is not writable so void 0 and undefined most likely the same. For older browser, undefined is actually a global property and can be changed, It is better to use void 0. ... void 0 is safer and can be used in place of undefined. One more advantage is to less type than undefined :) ... In this post, we saw the differences among undefined, null, NaN, empty string and undeclared variable & properties.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › undefined-vs-null-in-javascript
Undefined Vs Null in JavaScript - GeeksforGeeks
July 23, 2025 - undefined indicates a variable hasn’t been initialized, while null is intentionally assigned to indicate no value. Understanding the distinction helps write cleaner, more predictable code in JavaScript, especially when handling default values or checking for missing data.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › what-are-undeclared-and-undefined-variables-in-javascript
What are undeclared and undefined variables in JavaScript? - ...
June 20, 2023 - Undefined: It occurs when a variable has been declared but has not been assigned any value. Undefined is not a keyword. Undeclared: It occurs when we try to access any variable that is not initialized or declared earlier using the var or const ...
🌐
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
May 2, 2023 - Absolutely zero code ever speaks someNonExistentVariable into existence; it is completely undeclared ... null is for us to use, in our programs, to tell someone, “The object you wanted isn’t there; here’s an object you don’t want” · undefined is the default state of the JavaScript universe
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
You can also assign the null value ... 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....
🌐
Medium
medium.com › @jukemori › javascript-null-undefined-and-undeclared-explained-simply-111b8abcca98
JavaScript: null, undefined, and undeclared — Explained Simply | by Jun Ukemori | Sep, 2025 | Medium
September 27, 2025 - JavaScript has three “no value” states that look similar but mean different things. Knowing them prevents subtle bugs. undefined → Default “no value.” Happens automatically. ... Undeclared → Variable not defined at all.
🌐
Syncfusion
syncfusion.com › blogs › post › null-vs-undefined-in-javascript
Null vs. Undefined in JavaScript | Syncfusion Blogs
December 10, 2024 - This statement will be evaluated as false if the variable undeclaredVar is: Not declared. Declared but not initialized (undefined). Declared but initialized to null or undefined. As a result, you can safely conclude that a variable is properly declared and has a valid value when the previous statement is evaluated as true. Easily build real-time apps with Syncfusion’s high-performance, lightweight, modular, and responsive JavaScript UI components.