How to Check If A Value Is Not A Number in Javascript

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…

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to Check If A Value Is Not A Number in Javascript." Ariessa Norramli | Sciencx - Sunday February 14, 2021, https://www.scien.cx/2021/02/14/how-to-check-if-a-value-is-not-a-number-in-javascript/
HARVARD
Ariessa Norramli | Sciencx Sunday February 14, 2021 » How to Check If A Value Is Not A Number in Javascript., viewed ,<https://www.scien.cx/2021/02/14/how-to-check-if-a-value-is-not-a-number-in-javascript/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Check If A Value Is Not A Number in Javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/14/how-to-check-if-a-value-is-not-a-number-in-javascript/
CHICAGO
" » How to Check If A Value Is Not A Number in Javascript." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/14/how-to-check-if-a-value-is-not-a-number-in-javascript/
IEEE
" » How to Check If A Value Is Not A Number in Javascript." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/14/how-to-check-if-a-value-is-not-a-number-in-javascript/. [Accessed: ]
rf:citation
» How to Check If A Value Is Not A Number in Javascript | Ariessa Norramli | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.