All numbers in JavaScript are actually IEEE-754 compliant floating-point doubles. These have a 53-bit mantissa which should mean that any integer value with a magnitude of approximately 9 quadrillion or less -- more specifically, 9,007,199,254,740,991 -- will be represented accurately.


NOTICE: in 2018 main browsers and NodeJS are working also with the new Javascript's primitive-type, BigInt, solving the problems with integer value magnitude.

Answer from LukeH on Stack Overflow
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Number
Number - JavaScript | MDN
A number literal like 37 in JavaScript code is a floating-point value, not an integer. There is no separate integer type in common everyday use. (JavaScript also has a BigInt type, but it's not designed to replace Number for everyday uses.
Discussions

Number of bits in Javascript numbers - Stack Overflow
I work in Javascript with integer numbers only (mainly adding numbers and shifting them). I wonder how big they can be without loosing any bits. For example, how big X can be such that 1 More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - new Number() vs Number() - Stack Overflow
Your shorthands may be simpler, but they are not as clear as using the Number/String/Boolean functions to do the same thing. 2014-01-03T11:20:18.393Z+00:00 ... @Nigel True, but among JavaScript programmers, the + prefix for Number coercion is common and (from what I can see) preferred. More on stackoverflow.com
๐ŸŒ stackoverflow.com
math - What is JavaScript's highest integer value that a number can go to without losing precision? - Stack Overflow
Is this defined by the language? Is there a defined maximum? Is it different in different browsers? More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - How can I check if a string is a valid number? - Stack Overflow
I'm hoping there's something in the same conceptual space as the old VB6 IsNumeric() function? More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_numbers.asp
JavaScript Numbers
If you add a string and a number, the result will be a string concatenation: let x = "10"; let y = 20; let z = x + y; Try it Yourself ยป ยท A common mistake is to expect this result to be 30: let x = 10; let y = 20; let z = "The result is: " + x + y; Try it Yourself ยป ยท A common mistake is to expect this result to be 102030: let x = 10; let y = 20; let z = "30"; let result = x + y + z; Try it Yourself ยป ยท The JavaScript interpreter works from left to right.
๐ŸŒ
JavaScript.info
javascript.info โ€บ tutorial โ€บ the javascript language โ€บ data types
Numbers
December 18, 2024 - Weโ€™re too lazy for that. Weโ€™ll try to write something like "1bn" for a billion or "7.3bn" for 7 billion 300 million. The same is true for most large numbers. In JavaScript, we can shorten a number by appending the letter "e" to it and specifying the zeroes count:
๐ŸŒ
Mozilla
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Guide โ€บ Numbers_and_strings
Numbers and strings - JavaScript | MDN
This chapter introduces the two most fundamental data types in JavaScript: numbers and strings. We will introduce their underlying representations, and functions used to work with and perform calculations on them.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-numbers
JavaScript Numbers - GeeksforGeeks
JavaScript numbers are primitive data types, and unlike other programming languages, you don't need to declare different numeric types like int, float, etc. JavaScript numbers are always stored in double-precision 64-bit binary format IEEE 754.
Published ย  July 11, 2025
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_number_methods.asp
JavaScript Number Methods
The valueOf() method is used internally in JavaScript to convert Number objects to primitive values.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Number โ€บ MAX_SAFE_INTEGER
Number.MAX_SAFE_INTEGER - JavaScript | MDN
Number.MAX_SAFE_INTEGER represents ... The largest representable number in JavaScript is actually Number.MAX_VALUE, which is approximately 1.7976931348623157 ร— 10308....
๐ŸŒ
DEV Community
dev.to โ€บ imsushant12 โ€บ a-guide-to-master-numbers-data-type-in-javascript-37m4
A Guide to Master Numbers Data Type in JavaScript - DEV Community
July 20, 2024 - In this article, we'll explore the various number functions in JavaScript, providing detailed explanations, examples, and comments to help you master them.
๐ŸŒ
Mozilla
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Guide โ€บ Data_structures
JavaScript data types and data structures - JavaScript | MDN
Variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned (and re-assigned) values of all types: ... let foo = 42; // foo is now a number foo = "bar"; // foo is now a string foo = true; // foo is now a boolean
Top answer
1 of 5
76

Boolean(expression) will simply convert the expression into a boolean primitive value, while new Boolean(expression) will create a wrapper object around the converted boolean value.

The difference can be seen with this:

Copy// Note I'm using strict-equals
new Boolean("true") === true; // false
Boolean("true") === true; // true

And also with this (thanks @hobbs):

Copytypeof new Boolean("true"); // "object"
typeof Boolean("true"); // "boolean"

Note: While the wrapper object will get converted to the primitive automatically when necessary (and vice versa), there is only one case I can think of where you would want to use new Boolean, or any of the other wrappers for primitives - if you want to attach properties to a single value. E.g:

Copyvar b = new Boolean(true);
b.relatedMessage = "this should be true initially";
alert(b.relatedMessage); // will work

var b = true;
b.relatedMessage = "this should be true initially";
alert(b.relatedMessage); // undefined
2 of 5
40
Copynew Number( x )

creates a new wrapper object. I don't think that there is a valid reason to ever use this.

CopyNumber( x )

converts the passed argument into a Number value. You can use this to cast some variable to the Number type. However this gets the same job done:

Copy+x

Generally:

You don't need those:

Copynew Number()
new String()
new Boolean()

You can use those for casting:

CopyNumber( value )
String( value )
Boolean( value )

However, there are simpler solutions for casting:

Copy+x // cast to Number
'' + x // cast to String
!!x // cast to Boolean
Top answer
1 of 16
1011

JavaScript has two number types: Number and BigInt.

The most frequently-used number type, Number, is a 64-bit floating point IEEE 754 number.

The largest exact integral value of this type is Number.MAX_SAFE_INTEGER, which is:

  • 253-1, or
  • +/- 9,007,199,254,740,991, or
  • nine quadrillion seven trillion one hundred ninety-nine billion two hundred fifty-four million seven hundred forty thousand nine hundred ninety-one

To put this in perspective: one quadrillion bytes is a petabyte (or one thousand terabytes).

"Safe" in this context refers to the ability to represent integers exactly and to correctly compare them.

From the spec:

Note that all the positive and negative integers whose magnitude is no greater than 253 are representable in the Number type (indeed, the integer 0 has two representations, +0 and -0).

To safely use integers larger than this, you need to use BigInt, which has no upper bound.

Note that the bitwise operators and shift operators operate on 32-bit integers, so in that case, the max safe integer is 231-1, or 2,147,483,647.

const log = console.log
var x = 9007199254740992
var y = -x
log(x == x + 1) // true !
log(y == y - 1) // also true !

// Arithmetic operators work, but bitwise/shifts only operate on int32:
log(x / 2)      // 4503599627370496
log(x >> 1)     // 0
log(x | 1)      // 1


Technical note on the subject of the number 9,007,199,254,740,992: There is an exact IEEE-754 representation of this value, and you can assign and read this value from a variable, so for very carefully chosen applications in the domain of integers less than or equal to this value, you could treat this as a maximum value.

In the general case, you must treat this IEEE-754 value as inexact, because it is ambiguous whether it is encoding the logical value 9,007,199,254,740,992 or 9,007,199,254,740,993.

2 of 16
509

>= ES6:

Number.MIN_SAFE_INTEGER;
Number.MAX_SAFE_INTEGER;

<= ES5

From the reference:

Number.MAX_VALUE;
Number.MIN_VALUE;

console.log('MIN_VALUE', Number.MIN_VALUE);
console.log('MAX_VALUE', Number.MAX_VALUE);

console.log('MIN_SAFE_INTEGER', Number.MIN_SAFE_INTEGER); //ES6
console.log('MAX_SAFE_INTEGER', Number.MAX_SAFE_INTEGER); //ES6

Top answer
1 of 16
3311

2nd October 2020: note that many bare-bones approaches are fraught with subtle bugs (eg. whitespace, implicit partial parsing, radix, coercion of arrays etc.) that many of the answers here fail to take into account. The following implementation might work for you, but note that it does not cater for number separators other than the decimal point ".":

function isNumeric(str) {
  if (typeof str != "string") return false // we only process strings!  
  return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
         !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
}

To check if a variable (including a string) is a number, check if it is not a number:

This works regardless of whether the variable content is a string or number.

isNaN(num)         // returns true if the variable does NOT contain a valid number

Examples

isNaN(123)         // false
isNaN('123')       // false
isNaN('1e10000')   // false (This translates to Infinity, which is a number)
isNaN('foo')       // true
isNaN('10px')      // true
isNaN('')          // false
isNaN(' ')         // false
isNaN(false)       // false

Of course, you can negate this if you need to. For example, to implement the IsNumeric example you gave:

function isNumeric(num){
  return !isNaN(num)
}

To convert a string containing a number into a number:

Only works if the string only contains numeric characters, else it returns NaN.

+num               // returns the numeric value of the string, or NaN 
                   // if the string isn't purely numeric characters

Examples

+'12'              // 12
+'12.'             // 12
+'12..'            // NaN
+'.12'             // 0.12
+'..12'            // NaN
+'foo'             // NaN
+'12px'            // NaN

To convert a string loosely to a number

Useful for converting '12px' to 12, for example:

parseInt(num)      // extracts a numeric value from the 
                   // start of the string, or NaN.

Examples

parseInt('12')     // 12
parseInt('aaa')    // NaN
parseInt('12px')   // 12
parseInt('foo2')   // NaN      These last three may
parseInt('12a5')   // 12       be different from what
parseInt('0x10')   // 16       you expected to see.

Floats

Bear in mind that, unlike +num, parseInt (as the name suggests) will convert a float into an integer by chopping off everything following the decimal point (if you want to use parseInt() because of this behaviour, you're probably better off using another method instead):

+'12.345'          // 12.345
parseInt(12.345)   // 12
parseInt('12.345') // 12

Empty strings

Empty strings may be a little counter-intuitive. +num converts empty strings or strings with spaces to zero, and isNaN() assumes the same:

+''                // 0
+'   '             // 0
isNaN('')          // false
isNaN('   ')       // false

But parseInt() does not agree:

parseInt('')       // NaN
parseInt('   ')    // NaN
2 of 16
239

If you're just trying to check if a string is a whole number (no decimal places), regex is a good way to go. Other methods such as isNaN are too complicated for something so simple.

function isNumeric(value) {
    return /^-?\d+$/.test(value);
}

console.log(isNumeric('abcd'));         // false
console.log(isNumeric('123a'));         // false
console.log(isNumeric('1'));            // true
console.log(isNumeric('1234567890'));   // true
console.log(isNumeric('-23'));          // true
console.log(isNumeric(1234));           // true
console.log(isNumeric(1234n));          // true
console.log(isNumeric('123.4'));        // false
console.log(isNumeric(''));             // false
console.log(isNumeric(undefined));      // false
console.log(isNumeric(null));           // false

To only allow positive whole numbers use this:

function isNumeric(value) {
    return /^\d+$/.test(value);
}

console.log(isNumeric('123'));          // true
console.log(isNumeric('-23'));          // false
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ javascript โ€บ javascript number object
JavaScript Number Object
September 1, 2008 - Other types of data such as strings, etc., can be converted to numbers using Number() function. A JavaScript number is always stored as a floating-point value (decimal number). JavaScript does not make a distinction between integer values and ...
๐ŸŒ
Programiz
programiz.com โ€บ javascript โ€บ numbers
JavaScript Number (with Examples)
In JavaScript, numbers are used to represent numerical values. They can be whole numbers (like 5, 10, 100) or decimal numbers (like 3.13, 0.5, 10.75).