Course Content
Introduction to JavaScript (staging)
Introduction to JavaScript (staging)
Null vs Undefined
Similarities Between null
and undefined
- Both are Falsy:
A falsy (sometimes written falsey) value is a value that is considered asfalse
when encountered in a Boolean context. There are six-falsy-value in JavaScript.NaN
(Not A Number)0
(Zero)- null
- undefined
- '' (empty string)
false
Any value other than the above six falsy values, in JavaScript, will be considered as truthy.
- Both are Primitive Values:
JavaScript has seven primitive values includingnull
andundefined
. Here is a full list:- Null
- Undefined
- String
- Number
- BigInt
- Symbol
- Boolean
null
!== undefined
:
Although null
and undefined
share some similarities but they are different from each other and it is obvious that the null
and undefined
are not strictly equal.
console.log(null === undefined);
But null
loosely equals undefined
.
console.log(null == undefined)
As we talk in the previous chapter ==
checks the loose equality. But In JavaScript, a double equals tests for loose equality and it performs type coercion. type coercion means converting the value to the common type. But ===
does not perform type type coercion.
Summary:
- The
undefined
variables are those variables that are declared without any values assigned to them. null
is not assigned to a variable by default like theundefined
.- Both the
null
andundefined
are falsy values.
Thanks for your feedback!
Null vs Undefined
Similarities Between null
and undefined
- Both are Falsy:
A falsy (sometimes written falsey) value is a value that is considered asfalse
when encountered in a Boolean context. There are six-falsy-value in JavaScript.NaN
(Not A Number)0
(Zero)- null
- undefined
- '' (empty string)
false
Any value other than the above six falsy values, in JavaScript, will be considered as truthy.
- Both are Primitive Values:
JavaScript has seven primitive values includingnull
andundefined
. Here is a full list:- Null
- Undefined
- String
- Number
- BigInt
- Symbol
- Boolean
null
!== undefined
:
Although null
and undefined
share some similarities but they are different from each other and it is obvious that the null
and undefined
are not strictly equal.
console.log(null === undefined);
But null
loosely equals undefined
.
console.log(null == undefined)
As we talk in the previous chapter ==
checks the loose equality. But In JavaScript, a double equals tests for loose equality and it performs type coercion. type coercion means converting the value to the common type. But ===
does not perform type type coercion.
Summary:
- The
undefined
variables are those variables that are declared without any values assigned to them. null
is not assigned to a variable by default like theundefined
.- Both the
null
andundefined
are falsy values.
Thanks for your feedback!
Null vs Undefined
Similarities Between null
and undefined
- Both are Falsy:
A falsy (sometimes written falsey) value is a value that is considered asfalse
when encountered in a Boolean context. There are six-falsy-value in JavaScript.NaN
(Not A Number)0
(Zero)- null
- undefined
- '' (empty string)
false
Any value other than the above six falsy values, in JavaScript, will be considered as truthy.
- Both are Primitive Values:
JavaScript has seven primitive values includingnull
andundefined
. Here is a full list:- Null
- Undefined
- String
- Number
- BigInt
- Symbol
- Boolean
null
!== undefined
:
Although null
and undefined
share some similarities but they are different from each other and it is obvious that the null
and undefined
are not strictly equal.
console.log(null === undefined);
But null
loosely equals undefined
.
console.log(null == undefined)
As we talk in the previous chapter ==
checks the loose equality. But In JavaScript, a double equals tests for loose equality and it performs type coercion. type coercion means converting the value to the common type. But ===
does not perform type type coercion.
Summary:
- The
undefined
variables are those variables that are declared without any values assigned to them. null
is not assigned to a variable by default like theundefined
.- Both the
null
andundefined
are falsy values.
Thanks for your feedback!
Similarities Between null
and undefined
- Both are Falsy:
A falsy (sometimes written falsey) value is a value that is considered asfalse
when encountered in a Boolean context. There are six-falsy-value in JavaScript.NaN
(Not A Number)0
(Zero)- null
- undefined
- '' (empty string)
false
Any value other than the above six falsy values, in JavaScript, will be considered as truthy.
- Both are Primitive Values:
JavaScript has seven primitive values includingnull
andundefined
. Here is a full list:- Null
- Undefined
- String
- Number
- BigInt
- Symbol
- Boolean
null
!== undefined
:
Although null
and undefined
share some similarities but they are different from each other and it is obvious that the null
and undefined
are not strictly equal.
console.log(null === undefined);
But null
loosely equals undefined
.
console.log(null == undefined)
As we talk in the previous chapter ==
checks the loose equality. But In JavaScript, a double equals tests for loose equality and it performs type coercion. type coercion means converting the value to the common type. But ===
does not perform type type coercion.
Summary:
- The
undefined
variables are those variables that are declared without any values assigned to them. null
is not assigned to a variable by default like theundefined
.- Both the
null
andundefined
are falsy values.