Loading topic
int, long, float, and double. JavaScript's everyday arithmetic uses a single type, Number, for all of these. Integers like 42 and fractions like 0.75 are stored in the same 64-bit format and follow the same rule5 min read=== and typeof. It also builds on the previous chapter: every number you write ends up as one 64-bit IEEE 754 double, whatever syntax you used to write it.4 min read=== and typeof do. It also assumes you have read the earlier chapters: JavaScript has a single Number type, stored as a 64-bit IEEE 754 double.5 min read===. It builds on the earlier chapter about how every Number is a 64-bit IEEE 754 double. Here you will see why some decimal arithmetic comes out slightly wrong, where the error come5 min read=== and typeof. It also builds on the earlier chapters about the IEEE 754 double format and the arithmetic operators. IEEE 754 sets aside some bit patterns for results that are not ordinary numbers. Ja4 min read===, typeof, and running code in Node.js or a browser console. Earlier chapters showed that fractions such as 0.1 get rounded. This chapter shows that large whole numbers4 min readdata-* attributes all give you strings. JavaScript has four common ways to turn those strings into numbers, and they disagree on many inputs. This chapter shows the rule each one follows, where they4 min readNaN, Infinity, and -0 behave. You should know where the safe integer range ends, at Number.MAX_SAFE_INTEGER. You should also know how Number() converts strings. Here we use those ideas to answer a4 min read1.005 are not stored exactly, and how numeric literals such as 0xff and 1_000_000 are written. Those topics are covered in earlier chapters. This chapter covers what happens when you turn a number 5 min readMath that collects constants and functions for numeric work. This chapter explains what kind of object Math is, which constants it provides, how its methods treat the4 min read0.1 + 0.2 is not exactly 0.3, and how -0 and NaN behave. Those topics come from earlier chapters. Here you will learn the four basic ways to turn a fractional number into an integer, where each one surprises pe4 min readMath functions that you will reach for constantly: Math.max, Math.min, Math.abs, and Math.sign. They look trivial, but each one converts its arguments, reacts to NaN, and has rules for -0 and empty input that can catch you out.4 min read** operator, and that you understand why binary floating point rounds values like 0.1. All examples run unchanged in Node.js or a browser console.4 min readMath.floor and Math.round behave from the previous chapter, and that you can run JavaScript in Node.js (version 19 or later) or a browser console. It covers how to turn Math.random() into integers you can trust for games, sampling, and UI work. It also explain4 min read% keeps the sign of the dividend. You should remember a little school trigonometry: sine and cosine on a unit circle, and what an an4 min readMath.trunc differs from Math.floor. You should also be able to read numbers written in binary (0b) and hexadecimal (0x).4 min readNumber.MAX_SAFE_INTEGER is 2 ** 53 - 1, and integers above it can no longer be told apart reliably. It also assumes you know the arithmetic operators, typeof, and strict equality. Here you will learn how BigInt fixes4 min read