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
Fundamentals
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.
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.
Foundation
📝 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 value → 0.
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"
Cheat Sheet
⚡ Quick Reference
Goal
Code
Create a number (preferred)
42 or 3.14
Convert any value
Number(value)
Number object (avoid)
new Number(42)
Check primitive
typeof n === "number"
Check Number object
n instanceof Number
BigInt → Number
Number(1n)
Object vs primitive ===
false even if values match
Snapshot
🔍 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
Compare
📋 Literal vs Number() vs new Number()
Literal 123
Number("123")
new Number("123")
typeof
"number"
"number"
"object"
instanceof Number
false
false
true
=== 123
true
true
false
Best for?
Known values
Conversion
Almost never
Hands-On
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"
=== 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.
Applications
🚀 Common Use Cases
Form / API input — Number(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 zero — Number() 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.
Important
📝 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.
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · 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.
Wrap Up
Conclusion
The Number constructor is your conversion tool: Number(value) returns a number primitive, while new Number(value) returns a rarely useful object wrapper.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about the Number constructor
Convert with Number(); avoid new Number().
5
Core concepts
🔢01
Convert
Number(x)
API
📄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).