What is a Number in TypeScript?
This lesson delves into how to define integers, floats, and doubles in TypeScript.
We'll cover the following...
Another common primitive is the number. Since TypeScript is a superset of JavaScript, numbers work the same way in both languages. The openness of JavaScript allows for a broad set of numbers. Integers, signed floats, or unsigned floats are permitted. By default, a number will be base 10.
When a type is explicitly assigned to a variable, the type will be removed once the JavaScript is generated. The reason is that typing does not exist in JavaScript. It explains why TypeScript only has number
. The following code will produce three variables without an explicit type in JavaScript but if typeof
is used, it will return the dynamic type: number
.
const x: number = 10;let z: number = 15;var p: number = 123;console.log("Here are 3 variables of type number", x, z, p);
Number base
You can also assign base 16 (hexadecimal), base 8 ...