TypeScript supports all primitive JavaScript types—boolean, number, string, bigint, symbol, undefined, and null—and allows you to explicitly annotate variables or rely on automatic type inference.
string: Textual data (e.g., 'hello', "world", `template string`).number: Floating point numbers and integers (e.g., 42, 3.14159, 0xFF).boolean: Truth values (true or false).bigint: Large integers beyond Number.MAX_SAFE_INTEGER (e.g., 9007199254740991n).symbol: Unique immutable primitive values created via Symbol().// Explicit type annotations
const appName: string = "Analytics Engine";
const maxConnections: number = 100;
const isDebugEnabled: boolean = false;
const globalTransactionId: bigint = 9007199254740993n;
const processKey: symbol = Symbol("processKey");
function calculateTotalTax(amount: number, taxRate: number): number {
return amount * taxRate;
}
const itemPrice: number = 299.99;
const rate: number = 0.15;
const totalTax: number = calculateTotalTax(itemPrice, rate);
console.log(`[${appName}] Total Tax on \$${itemPrice}: \$${totalTax.toFixed(2)}`);
string, number, boolean), not capitalized Object wrappers (String, Number, Boolean).const count = 5;, explicit const count: number = 5; is unnecessary.NaN: NaN is technically of type number in TypeScript/JavaScript; always check Number.isNaN() when parsing numbers.Declare a variable userAge with explicit type number and set it to 25. Attempt to assign "twenty-five" to it and note the compiler error message.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With