# How to check if a value is a number in JavaScript

> Learn how to check if a value is a number in JavaScript using the isNaN() function or the typeof operator, which returns number for numeric values.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-06-21 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/how-to-check-value-is-number-javascript/

We have various ways to check if a value is a number.

The first is `isNaN()`, a global variable, assigned to the `window` object in the browser:

```js
const value = 2

isNaN(value) //false

isNaN('test') //true

isNaN({}) //true

isNaN(1.2) //false
```

If `isNaN()` returns false, the value **is** a number.

Another way is to use the `typeof` operator. It returns the `'number'` string if you use it on a number value:

```js
typeof 1 //'number'

const value = 2

typeof value //'number'
```

So you can do a conditional check like this:

```js
const value = 2
if (typeof value === 'number') {
  //it's a number
}
```
