Numbers: Number Basics

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


Creating Numbers

A number value can be generated using a number literal syntax:

const age = 36
typeof age //number

or using the Number global function:

const age = Number(36)
typeof age //number

If we add the new keyword, we get a Number object in return:

const age = new Number(36)
typeof age //object

which has a very different behavior than a number type. You can get the original number value using the valueOf() method:

const age = new Number(36)
typeof age //object
age.valueOf() //36

Number Properties

The Number object has several useful properties:

  • EPSILON the smallest interval between two numbers
  • MAX_SAFE_INTEGER the maximum integer value JavaScript can represent
  • MAX_VALUE the maximum positive value JavaScript can represent
  • MIN_SAFE_INTEGER the minimum integer value JavaScript can represent
  • MIN_VALUE the minimum positive value JavaScript can represent
  • NaN a special value representing “not a number”
  • NEGATIVE_INFINITY a special value representing negative infinity
  • POSITIVE_INFINITY a special value representing positive infinity

Those properties evaluated to the values listed below:

Number.EPSILON           //2.220446049250313e-16
Number.MAX_SAFE_INTEGER  //9007199254740991
Number.MAX_VALUE         //1.7976931348623157e+308
Number.MIN_SAFE_INTEGER  //-9007199254740991
Number.MIN_VALUE         //5e-324
Number.NaN               //NaN
Number.NEGATIVE_INFINITY //-Infinity
Number.POSITIVE_INFINITY //Infinity

Safe Integers

A safe integer is an integer that can be exactly represented as an IEEE-754 double precision number (all integers from (2^53 - 1) to -(2^53 - 1)). Out of this range, integers cannot be represented by JavaScript correctly.

NaN

NaN is a special value that represents “Not a Number”. It’s returned when a mathematical operation doesn’t result in a valid number:

0 / 0        //NaN
Math.sqrt(-1) //NaN
parseInt('hello') //NaN

NaN has the unique property of not being equal to itself:

NaN === NaN //false

Use Number.isNaN() to check if a value is NaN.

Infinity

JavaScript has special values for positive and negative infinity:

1 / 0  //Infinity
-1 / 0 //-Infinity

You can check for infinity using Number.isFinite().

valueOf() Method

This method returns the number value of a Number object:

const age = new Number(36)
typeof age //object
age.valueOf() //36

Lessons in this unit:

0: Introduction
1: ▶︎ Number Basics
2: Number Validation
3: Parsing Numbers
4: Formatting Numbers
5: Number Recipes
6: The Binary Number System
7: Underscores in numbers
8: The Decimal Number System
9: Converting Numbers from Decimal to Binary