number (type)
The type of ordinary numeric values in JavaScript, both whole numbers and decimals, stored as 64-bit floating-point numbers.
In more detail
Because of the floating-point format, whole numbers are only exact up to Number.MAX_SAFE_INTEGER, and decimals such as 0.1 + 0.2 are slightly off. Use bigint for larger integers and whole units such as cents for money.
Related terms
- MAX_SAFE_INTEGER — The largest whole number, 9007199254740991, that a JavaScript number can store exactly.
- bigint — A primitive type for whole numbers of any size, written with an n suffix such as 9007199254740993n.
- floating-point number — A number with a fractional part stored in binary, which can only approximate most decimal values.
- primitive type — A basic built-in type, such as a whole number or true-or-false, whose values are held directly rather than as objects.
Taught in
- The Compiler Pipeline: tsc, AST And Code Emission — Production TypeScript
- Type Annotations, Type Inference And Contextual Typing — Production TypeScript
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- Primitive Types: String, Number, Boolean, Bigint And Symbol — Production TypeScript
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- any Versus unknown: Defensive Typing In Practice — Production TypeScript
- never: The Bottom Type And Exhaustive Switch Checking — Production TypeScript
- Optional Properties, Readonly And Index Signatures — Production TypeScript
- Union Types, Intersections And Property Conflicts — Production TypeScript
- Discriminated Unions: Tagged Variants And Pattern Matching — Production TypeScript
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- Typeof Guards, Truthiness And Equality Narrowing — Production TypeScript
- The in Operator And Instanceof Narrowing — Production TypeScript
- Custom Type Predicates: Functions Returning is Type — Production TypeScript
- Exhaustive Narrowing With never In Production Handlers — Production TypeScript
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- Generic Interfaces, Classes And Type Aliases — Production TypeScript
- Generic Constraints: extends, keyof And Indexed Access — Production TypeScript
- Default Generic Arguments And Multi-Type Parameters — Production TypeScript
- Union Utilities: Exclude, Extract, NonNullable And Awaited — Production TypeScript
- Conditional Types: Ternary Types And Type Inference With infer — Production TypeScript
- Mapped Types, Key Remapping With as And Template Literals — Production TypeScript
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript
- The satisfies Operator: Safe Validation Without Widening — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript
- The Spine Artifact: Generating Typed Models From OpenAPI — Production TypeScript