Foundations
Variables and Types
Use const for values that are not reassigned and let for values that change.
Variables
variables.ts
const unitPrice: number = ;
let quantity: number = 3;
const label: string = "notebook";
const subtotal: number = unitPrice * quantity;
quantity = quantity + 1;
const nextSubtotal: number = unitPrice * quantity;
console.log(`${label}: ${quantity} items`);
console.log(`Before restock: $${subtotal}`);
console.log(`After restock: $${nextSubtotal}`);
const unitPrice: number = ;
let quantity: number = 3;
const label: string = "notebook";
const subtotal: number = unitPrice * quantity;
quantity = quantity + 1;
const nextSubtotal: number = unitPrice * quantity;
console.log(`${label}: ${quantity} items`);
console.log(`Before restock: $${subtotal}`);
console.log(`After restock: $${nextSubtotal}`);
const unitPrice: number = ;
let quantity: number = 3;
const label: string = "notebook";
const subtotal: number = unitPrice * quantity;
quantity = quantity + 1;
const nextSubtotal: number = unitPrice * quantity;
console.log(`${label}: ${quantity} items`);
console.log(`Before restock: $${subtotal}`);
console.log(`After restock: $${nextSubtotal}`);
const and let
`const` protects a binding from reassignment, while `let` marks a binding that can change later.