This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to Check If A Value Is Not A Number in Javascript.
Let’s say you have 5 types of variables.
// 1: A number variable named 'a' with the value 123
var a = 123;
// 2: A string variable named 'b' with the value "codesource"
var b = "codesource";
// 3: A boolean variable named 'c' with the value true
var c = true;
// 4: An undefined variable named 'd' with the value undefined
var d;
// 5: A null variable named 'e' with the value null
var e = null;
In order to check if a variable’s value is a number or not, you can use the isNaN()
method.
var a = 123;
var b = “codesource”;
var c = true;
var d;
var e = null;
console.log(isNaN(a));
console.log(isNaN(b));
console.log(isNaN(c));
console.log(isNaN(d));
console.log(isNaN(e));
Note: The word NaN
stands for Not A Number. The isNaN
method functions by checking whether a value is a legitimate number or not in Javascript. It will return true if the value is not a number. Else, it will return false.
The post How to Check If A Value Is Not A Number in Javascript appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-14T17:19:51+00:00) How to Check If A Value Is Not A Number in Javascript. Retrieved from https://www.scien.cx/2021/02/14/how-to-check-if-a-value-is-not-a-number-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.