Horje
What does !== undefined mean in JavaScript ?

In JavaScript, !== is a strict inequality operator, and undefined is a special value representing the absence of a value or the lack of an assigned value to a variable. The !== operator checks for both value and type equality, and !== undefined is used to verify if a variable is not equal to the undefined value.

Using strict inequality

The !== operator checks for both value and type equality, and !== undefined is used to verify if a variable is not equal to the undefined value.

Example: To demonstrate the use of the strict inequality operator by checking whether a number is undefined or not.

Javascript

let num = 5;
 
if (num !== undefined) {
  console.log(num);
} else {
  console.log(undefined);
}

Output

5

Using equality operator with negation

The non-strict equality operator != lead to unexpected behaviour in certain cases. Using the strict inequality operator !== is generally recommended for checking against undefined.

Example: To demonstrate using equality operator with negation.

Javascript

let num;
 
if (num != undefined) {
  console.log("num has a value assigned.");
} else {
  console.log("num is undefined.");
}

Output

num is undefined.



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
How to Convert an Object into Array of Objects in JavaScript ? How to Convert an Object into Array of Objects in JavaScript ?
How to Parse Float with Two Decimal Places in TypeScript ? How to Parse Float with Two Decimal Places in TypeScript ?
How to Add an Image File to an Object of an Array in JavaScript ? How to Add an Image File to an Object of an Array in JavaScript ?
How to Display a Placeholder for Phone Numbers in jQuery ? How to Display a Placeholder for Phone Numbers in jQuery ?
How to Remove Spaces from a String in TypeScript ? How to Remove Spaces from a String in TypeScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
9