Skip to content
Latest: Publish JavaScript Packages to NPM Like a Pro!

Number() in JavaScript – How to Convert Values to Numbers

Whenever you invoke Number(), the method converts its argument to a number.

JavaScript Number() global method's
tidbit

Use JavaScript’s Number() method to convert a value to a Number type or NaN.

Number() accepts only one argument. Here is the syntax:

Number(value);

Example 1: Convert String Number to Number Type

Section titled “Example 1: Convert String Number to Number Type”
Number("578");
// The invocation above will return: 578

Try Editing It

Example 2: Convert String Text to Number Type

Section titled “Example 2: Convert String Text to Number Type”
Number("Pink");
// The invocation above will return: NaN

Try it on CodePen

Number(true);
// The invocation above will return: 1

Try Editing It

Number(false);
// The invocation above will return: 0

Try Editing It

Number(new Date(2022, 06, 01));
// The invocation above will return: 1656630000000

Try Editing It