JavaScript Number() Constructor

Beginner
5 min read
Updated: Nov 2026
4 examples
Constructor

Definition

The global Number function converts a value to a number primitive when called without new. With new, it returns a Number object wrapper. It is Baseline Widely available.

Pass the required arguments shown below. Prefer Number(value) for coercion; avoid new Number() unless you need an object wrapper.

Syntax

Create or coerce a number. Start with this line.

JavaScript
Number(value) / new Number(value)
CallWhat it does
Number(value) / new Number(value)Primary signature.

Built into JavaScript. Call Number(...) (prefer without new) — no import required.

Library declarations
JavaScript
Number(value) / new Number(value)

Parameters

ParameterDescription
valueOptional. Value to coerce; omit → 0

Return Value

Return ValueDescription
*Number primitive (typeof "number")

JavaScript Examples

Example 1 — Number() vs new Number()

Same digits, different kinds of values.

JavaScript
const a = new Number("123");
const b = Number("123");

console.log(a === 123);           // false
console.log(b === 123);           // true
console.log(a instanceof Number); // true
console.log(b instanceof Number); // false
console.log(typeof a);            // "object"
console.log(typeof b);            // "number"
Try It Yourself

How It Works

  1. Object form. new Number("123") wraps the value → typeof "object".
  2. Function form. Number("123") returns the primitive 123.
  3. Strict equality. Object vs primitive → a === 123 is false; b === 123 is true.
  4. instanceof. Only the wrapper is an instance of Number.

Example 2 — Convert Common Values

Everyday ToNumber results you will see often.

JavaScript
console.log(Number());          // 0
console.log(Number(""));        // 0
console.log(Number("  42  "));  // 42
console.log(Number(true));      // 1
console.log(Number(null));      // 0
console.log(Number(undefined)); // NaN
console.log(Number("abc"));     // NaN
Try It Yourself

How It Works

  1. Defaults. Missing argument and empty string both become 0.
  2. Trim digits. Whitespace around a numeric string is ignored → 42.
  3. Booleans & null. true → 1; null → 0.
  4. Failures. undefined and bad text become NaN.

Example 3 — Convert a BigInt with Number()

Number() is the explicit BigInt → Number path (unary + throws).

JavaScript
console.log(Number(1n));  // 1

try {
  console.log(+1n);
} catch (e) {
  console.log(e.name);    // TypeError
}

try {
  console.log(0 + 1n);
} catch (e) {
  console.log(e.name);    // TypeError
}
Try It Yourself

How It Works

  1. Explicit convert. Number(1n) is allowed and returns 1.
  2. Unary plus refuses. +1n throws TypeError.
  3. Mixed math refuses. 0 + 1n also throws — use an explicit cast.
  4. Precision care. Very large BigInts may not round-trip through Number exactly (see edge cases).

Example 4 — Equality Trap with Objects

Why new Number surprises beginners with ===.

JavaScript
const wrapped = new Number(10);
const primitive = Number(10);

console.log(wrapped === 10);           // false
console.log(primitive === 10);         // true
console.log(wrapped.valueOf() === 10); // true
console.log(Number(wrapped) === 10);   // true
Try It Yourself

How It Works

  1. No auto-unbox for ===. A Number object is not strictly equal to 10.
  2. Primitives compare cleanly. Number(10) === 10 is true.
  3. Escape hatch. .valueOf() or Number(wrapped) extracts the primitive.
  4. Best fix. Do not create Number objects — stay with literals and Number(x).

Browser & Runtime Support

The Number constructor is Baseline Widely available and supported in every modern browser and Node.js.

✓ Baseline · Widely available

Number() constructor

Safe for production everywhere. Prefer Number(value) for conversion; avoid new Number().

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Number() Excellent

Bottom line: Use Number(value) to coerce to a primitive. Avoid new Number(). Convert BigInts explicitly and watch precision past MAX_SAFE_INTEGER.

Frequently Asked Questions

Number is a built-in global. Call Number(value) without new to coerce value to a number primitive. Call new Number(value) to wrap that number in a Number object — rarely needed in everyday code.
Number("123") returns the primitive 123 (typeof "number"). new Number("123") returns a Number object (typeof "object"). Prefer the function form; MDN warns you should rarely use Number as a constructor.
Strict equality compares type and value. A Number object and a number primitive are different types even when their numeric value matches. Prefer Number(value) or literals so you stay with primitives.
Yes. Number(1n) returns 1. Unary plus and mixed BigInt arithmetic throw, so Number() is the explicit conversion path. Large BigInts may lose precision when converted to Number.
Number() with no argument returns 0. Number(undefined) returns NaN. Number(null) returns 0. Number("") returns 0. Invalid numeric strings return NaN.
Number has been part of JavaScript since early editions. It is Baseline Widely available in every modern browser and Node.js.

Next: Number Methods

Learn toFixed, toString, isFinite, parseInt, and more Number helpers.

Number methods hub →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful