Horje
How to Check if a Variable is of Type Number in JavaScript ?

In JavaScript, you can check if a variable is of type number using the typeof operator. The typeof operator returns a string indicating the type of the operand.

Example: Here, typeof myVariable evaluates to the string 'number', and the === operator is used to check if it is equal to the string 'number'. If the condition is true, it means that the variable is of type number.

Javascript

let myVariable = 42;
 
if (typeof myVariable === 'number') {
    console.log('It is a number!');
} else {
    console.log('It is not a number.');
}

Output

It is a number!




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
How to Create a Single Line Comment in JavaScript ? How to Create a Single Line Comment in JavaScript ?
How to Create a Multi Line Comment in JavaScript ? How to Create a Multi Line Comment in JavaScript ?
How to Exit a Loop Before it Completes all Iterations in JavaScript ? How to Exit a Loop Before it Completes all Iterations in JavaScript ?
How to use the ! Operator to negate a Boolean Value in JavaScript ? How to use the ! Operator to negate a Boolean Value in JavaScript ?
What is the use of the Prompt Function in JavaScript ? What is the use of the Prompt Function in JavaScript ?

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