What is a Number in TypeScript?

This lesson delves into how to define integers, floats, and doubles in TypeScript.

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.

Get hands-on with 1200+ tech skills courses.