Work With Numbers in JavaScript I

JavaScript·2 min read·Jan 1, 2026

In JavaScript, the Number type represents numeric data, such as integers (e.g., 42, -2) and floating-point numbers (e.g, 3.14, -0.1), both positive and negative, and special values like NaN, Infinity, or -Infinity.

It is used for performing arithmetic operations, calculations, and also for storing user-facing values representing quantities or measurements.

Writing number literals

In JavaScript, numbers can be written in 4 different forms called bases including: decimal, hexadecimal, binary, and octal.

Decimal numbers (base 10)

Decimal numbers use digits 0-9.

They are the most common number system as they are used in everyday arithmetic and most general-purpose programming tasks, such as counters, prices, measurements, and so on.

For example:

// Integerconst age = 34;// Floating-pointconst pi = 3.14;

Hexadecimal numbers (base 16)

Hexadecimal numbers use digits 0-9 and letters 'A-F' (or 'a-f') to represent values 0-15, and are prefixed with 0x.

They are commonly used in computing to represent data in a shorter and more readable format, such as binary data, memory addresses, color codes, and more.

For example:

// 255 in base 10

Unlock the program 🚀

Pay once, own it forever.

€79

30-day money-back guarantee

  • 13 modules
  • 113 lessons with full-code examples
  • 29 projects with commented solutions
  • All future lesson and project updates
  • Lifetime access

By submitting this form, you agree to the Terms & Conditions and Privacy Policy.