Number 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
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.
Bedankt voor je feedback!
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 5.56
Number 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
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.
Bedankt voor je feedback!