JavaScript Number Constructor

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Global constructor

What You’ll Learn

The global Number function creates numbers in JavaScript—either as lightweight primitives or as wrapper objects (same API as MDN Number() constructor). Call it as a function for conversion; avoid new Number() in everyday code. This tutorial covers coercion rules, BigInt conversion, precision loss, five examples, and try-it labs.

01

Convert

Number("42")

02

Literal

42

03

Object

new Number()

04

BigInt

Number(1n)

05

Prefer

Primitives

06

Baseline

Everywhere

Introduction

Almost every number you write in JavaScript is a primitive (typeof "number" value — for example 42, 3.14, or Number("99").

Calling new Number(value) instead wraps that value in a Number object. Objects are heavier, fail some === checks against primitives, and are almost never what you want. MDN’s guidance is clear: you should rarely use Number as a constructor.

💡
Function vs constructor

Use Number(value) (no new) to coerce to a number primitive. Use a literal like 42 when you already know the value. Reach for new Number() only if you truly need a Number object.

Continue with Number methods and Number properties after you understand conversion.

Understanding the Number Constructor

When Number runs as a function, it applies ToNumber-style coercion: strings become numbers (or NaN), booleans become 0/1, null becomes 0, and undefined becomes NaN. BigInts are converted explicitly instead of throwing.

  • Number(value) → number primitive.
  • new Number(value) → Number object (avoid).
  • No argument: Number() returns 0.
  • Invalid text: Number("abc") returns NaN.

📝 Syntax

Two forms of the global Number function (from MDN):

JavaScript
Number(value)        // returns a number primitive
new Number(value)    // returns a Number object

Parameters

  • value (optional) — the value to convert or wrap. If omitted, the result is 0 (as a function) / a Number object wrapping 0 (with new).

Return value

  • Number(value)value coerced to a number primitive. BigInts convert instead of throwing. Missing value0.
  • new Number(value) — a Number object wrapping that coerced value (not a primitive).

Common patterns

JavaScript
Number("123");          // 123
Number("");             // 0
Number(true);           // 1
Number(null);           // 0
Number(undefined);      // NaN
Number("abc");          // NaN
Number(1n);             // 1  (explicit BigInt → Number)

const a = new Number("123");
const b = Number("123");
a === 123;              // false
b === 123;              // true
typeof a;               // "object"
typeof b;               // "number"

⚡ Quick Reference

GoalCode
Create a number (preferred)42 or 3.14
Convert any valueNumber(value)
Number object (avoid)new Number(42)
Check primitivetypeof n === "number"
Check Number objectn instanceof Number
BigInt → NumberNumber(1n)
Object vs primitive ===false even if values match

🔍 At a Glance

Four facts to remember about the Number constructor.

Convert
Number(x)

Returns primitive

Object
new Number(x)

Rare — avoid

No args
0

Number() → 0

BigInt
Number(1n)

Explicit convert

📋 Literal vs Number() vs new Number()

Literal 123Number("123")new Number("123")
typeof"number""number""object"
instanceof Numberfalsefalsetrue
=== 123truetruefalse
Best for?Known valuesConversionAlmost never

Examples Gallery

Examples follow MDN Number() constructor patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

See how Number() and new Number() differ at runtime.

Example 1 — Number() vs new Number()

Same digits, different kinds of values (MDN Creating Number objects).

JavaScript
const a = new Number("123"); // a === 123 is false
const b = Number("123");     // b === 123 is true

a instanceof Number;  // true
b instanceof Number;  // false
typeof a;             // "object"
typeof b;             // "number"
Try It Yourself

How It Works

Number("123") coerces to the primitive 123. new Number("123") builds a wrapper object. Prefer the function form.

📈 Practical Patterns

Everyday coercion, BigInt conversion, and precision traps.

Example 2 — Convert Common Values

Useful ToNumber results you will see every day.

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

How It Works

Whitespace around digits is trimmed. Empty string and null become 0. Bad text and undefined become NaN.

Example 3 — Convert a BigInt with Number()

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

JavaScript
// +1n;        // TypeError: Cannot convert a BigInt value to a number
// 0 + 1n;     // TypeError: Cannot mix BigInt and other types

Number(1n);    // 1
Try It Yourself

How It Works

Mixed BigInt arithmetic and unary + refuse the conversion. Number(bigint) is intentional and therefore allowed.

Example 4 — BigInt Precision Loss

Large integers may not round-trip through Number safely.

JavaScript
BigInt(Number(2n ** 54n + 1n)) === 2n ** 54n + 1n;  // false

Number(2n ** 54n + 1n);  // 18014398509481984  (precision lost)
Try It Yourself

How It Works

Past Number.MAX_SAFE_INTEGER, Number cannot represent every integer exactly. Keep large exact values as BigInt.

Example 5 — Equality Trap with Objects

Why new Number surprises beginners with ===.

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

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

How It Works

=== does not unbox for you. If you somehow have a Number object, call .valueOf() or pass it through Number() again — or better, never create the object.

🚀 Common Use Cases

  • Form / API inputNumber(input) then validate with Number.isFinite.
  • Normalize mixed types — booleans, numeric strings, and nullish values.
  • Explicit BigInt bridge — convert when you intentionally accept precision limits.
  • Default zeroNumber() or Number("") when empty means 0.
  • Teaching types — show why new Number breaks ===.
  • Not for parsing partial strings — prefer parseInt / parseFloat when text may have trailing junk.

🧠 How Number(value) Works

1

Receive a value

String, boolean, BigInt, null, undefined, or another number.

Input
2

Apply ToNumber rules

Coerce using ECMAScript conversion (BigInts allowed here).

Coerce
3

Return primitive or object

Function call → primitive. new → Number object.

Result
4

Validate when needed

Use Number.isFinite / Number.isNaN on the result.

📝 Notes

  • Prefer literals and Number(value) — not new Number().
  • Number("123abc") is NaN; parseInt("123abc") is 123.
  • Unary + also coerces, but throws on BigInt — Number() does not.
  • Number objects are still usable with methods via auto-unboxing, but stay with primitives.
  • Related constants live under Number properties.
  • Formatting helpers live under Number methods.

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.

Conclusion

The Number constructor is your conversion tool: Number(value) returns a number primitive, while new Number(value) returns a rarely useful object wrapper.

Continue with Number methods, Number properties, isFinite(), or NaN.

💡 Best Practices

✅ Do

  • Use numeric literals for known values
  • Call Number(value) for conversion
  • Validate with Number.isFinite(n) after coercion
  • Use Number(bigint) when converting BigInt intentionally
  • Prefer parseInt / parseFloat for partial numeric strings

❌ Don’t

  • Use new Number() in application code
  • Compare Number objects to primitives with === and expect true
  • Assume large BigInts survive Number conversion exactly
  • Confuse Number("12px") (NaN) with parseInt("12px")
  • Skip NaN / Infinity checks on user input

Key Takeaways

Knowledge Unlocked

Five things to remember about the Number constructor

Convert with Number(); avoid new Number().

5
Core concepts
📄 02

Kind

primitive

Result
03

new

avoid

Trap
🟢 04

BigInt

explicit

Convert
05

Safe int

watch size

Precision

❓ Frequently Asked Questions

Number is a built-in global function. 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"). Primitives are lighter and what you should use by default. 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.
Did you know?

JavaScript auto-boxes number primitives when you call methods like (42).toFixed(2). You get the Number API without ever writing new Number(42).

Explore Number Methods

Format, parse, and validate numbers next.

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.

8 people found this page helpful