Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Number Type | Core TypeScript Types
TypeScript Foundations

bookNumber Type

TypeScript uses the number type to represent both integer and floating-point values. This means you do not need to distinguish between whole numbers and decimals—TypeScript treats them all as number. You can use the number type for quantities like age, price, temperature, or any other numeric value.

123456789101112131415
// Declaring number variables let age: number = 30; // integer value let price: number = 19.99; // floating-point value // Arithmetic operations let total: number = age + price; let difference: number = age - price; let product: number = age * 2; let quotient: number = age / 3; // Output values console.log('Total:', total); // Total: 49.99 console.log('Difference:', difference); // Difference: 10.01 console.log('Product:', product); // Product: 60 console.log('Quotient:', quotient); // Quotient: 10
copy

TypeScript can often figure out the type of a variable automatically. This is called type inference. For example, if you write let temperature = 72;, TypeScript knows that temperature is a number because you assigned a numeric value. However, you can also use an explicit type annotation, such as let temperature: number = 72;, to make your intent clear. Both approaches are valid, but explicit annotations can help make your code easier to read and understand, especially in larger projects.

question mark

Which of the following is the correct way to declare a variable with the number type in TypeScript?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 1

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Awesome!

Completion rate improved to 5.56

bookNumber Type

Veeg om het menu te tonen

TypeScript uses the number type to represent both integer and floating-point values. This means you do not need to distinguish between whole numbers and decimals—TypeScript treats them all as number. You can use the number type for quantities like age, price, temperature, or any other numeric value.

123456789101112131415
// Declaring number variables let age: number = 30; // integer value let price: number = 19.99; // floating-point value // Arithmetic operations let total: number = age + price; let difference: number = age - price; let product: number = age * 2; let quotient: number = age / 3; // Output values console.log('Total:', total); // Total: 49.99 console.log('Difference:', difference); // Difference: 10.01 console.log('Product:', product); // Product: 60 console.log('Quotient:', quotient); // Quotient: 10
copy

TypeScript can often figure out the type of a variable automatically. This is called type inference. For example, if you write let temperature = 72;, TypeScript knows that temperature is a number because you assigned a numeric value. However, you can also use an explicit type annotation, such as let temperature: number = 72;, to make your intent clear. Both approaches are valid, but explicit annotations can help make your code easier to read and understand, especially in larger projects.

question mark

Which of the following is the correct way to declare a variable with the number type in TypeScript?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 1
some-alt