
Join the Conversation!
Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.
Learning Objective: Differentiate between and values and understand their unique roles in JavaScript.
is a special value in JavaScript used to represent “nothing,” “empty,” or “value unknown.” It is intentionally set by a programmer to indicate that a variable should have no value.
let age = null; // This means "age is unknown or empty."
console.log(age); // null
Key Points:
is the default value for variables that have been declared but not assigned a value.
let x; // No value assigned
console.log(x); // undefined
While it’s technically possible, it’s not recommended to assign manually. Use for this purpose instead.
let x = 123;
x = undefined; // Not recommended
console.log(x); // undefined
means a variable exists but doesn’t have a value:
let name; // Declared but not assigned
console.log(name); // undefined
means the variable intentionally has no value:
let name = null; // Explicitly set to "no value"
console.log(name); // null
They are not strictly equal:
console.log(null === undefined); // false
But they are loosely equal:
console.log(null == undefined); // true
You can inspect the type of any value using :
let empty = null;
let notSet;
console.log(typeof empty); // "object" (a JavaScript quirk!)
console.log(typeof notSet); // "undefined"
Example:
let empty = null; // null value
let notSet; // undefined
console.log(empty); // null
console.log(typeof empty); // "object"
console.log(notSet); // undefined
console.log(typeof notSet); // "undefined"
In this lesson, you learned the difference between and . These concepts are foundational for debugging and writing clear, intentional code. Practice working with them, and don’t forget to explore their behavior using !
Next, we’ll explore objects, a key data type in JavaScript that enables you to store and manage collections of data. Let’s keep going! 🚀
"Please login to view comments"
Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.
How did you manage to remove the blur property and reach here?
Upgrading gives you access to quizzes so you can test your knowledge, track progress, and improve your skills.
By logging in, you'll unlock full access to this and other free tutorials on JSM Pro.
Why? Logging in lets us personalize your learning experience, track your progress, and keep you in the loop with new workshops, coding tips, and platform updates.
You'll also be the first to know about upcoming launches, events, and exclusive discounts.
No spam—just helpful content to level up your skills.
If that sounds fair, go ahead and log in to continue →
Enter your name and email to get instant access
##Looks like we found a thief monkey By the way, I liked the trick how you reached till here. You have a good sense of humor. You will improve a lot if you join our course with this passion.
var
(function-scoped, outdated)let
(block-scoped, modern and recommended)const
(block-scoped, cannot be reassigned)_
, or $
let let = 5;
is invalid)myVar
and myvar
are different)string
, number
, boolean
, null
, undefined
, bigint
, symbol
Objects
, Arrays
, Functions
Subscribing gives you access to a brief, insightful summary of each lecture to stay on track.
00:00:00 So, what is null?
00:00:02 Well, null is a special value in JavaScript used to represent nothing, empty, or unknown value.
00:00:09 It is intentionally set by a programmer to indicate that a variable should have no value.
00:00:15 A simple example would look like this.
00:00:17 Let age is equal to null, which means that age is unknown or empty.
00:00:23 Pretty simple, right?
00:00:25 But a key point here is that null must be explicitly assigned to a variable.
00:00:31 So you use it at the start or you use it to reset a variable's value.
00:00:36 But then there's undefined.
00:00:38 And undefined, unlike null, doesn't have to be explicitly assigned.
00:00:42 Rather, it is the default value for variables that have been declared but not assigned a value.
00:00:49 It looks something like this.
00:00:50 Let X, but no equal sign in then something, rather it's empty, no value assigned.
00:00:57 Therefore, if you try to console log it, you get back undefined.
00:01:01 Now, could you define undefined explicitly?
00:01:04 Well, of course you could.
00:01:05 Let's say that X by default is set to one, two, three, but then you re-declare it to undefined, console log it, and hey,
00:01:12 it is undefined.
00:01:13 But this is not typically recommended.
00:01:15 If you want to reset the value, just rather use null.
00:01:20 We specifically use undefined when we know that the value doesn't yet exist.
00:01:24 So the key differences between null and undefined are that null represents no value and intentionally has no value.
00:01:32 But undefined is the default value for uninitialized variables.
00:01:37 So null is assigned by a programmer and undefined is assigned by JavaScript.
00:01:42 And the type of null is object, which is that JavaScript quirk we talked about, while the type of undefined is undefined,
00:01:50 which is its own type.
00:01:52 So in this lesson, you learned the difference between null and undefined.
00:01:56 And these concepts are foundational for debugging and writing clear and intentional code.
00:02:02 Practice working with them and don't forget to explore their behavior using the type of operator.
00:02:08 Next, let's explore objects, one of the key data types in JavaScript that enables you to store and manage collections of data.