100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
TypeScript

Primitive Types in TypeScript

A guided tour of TypeScript's built-in primitive types: string, number, boolean, null, undefined, bigint, and symbol.

Basic TypesBeginner9 min readJul 8, 2026
Analogies

1. Introduction

TypeScript builds directly on top of JavaScript's primitive types and adds static checking around them. The core primitives you will use daily are string, number, and boolean, alongside null, undefined, bigint, and symbol.

🏏

Cricket analogy: Just as cricket has a fixed set of dismissal types — bowled, caught, LBW, run out — TypeScript has a fixed set of primitives like string, number, and boolean that every value must conform to for static checking.

Understanding how TypeScript models each primitive — and where it diverges from other typed languages — is essential before moving on to arrays, objects, and more advanced type constructs.

🏏

Cricket analogy: Before analyzing complex data like a full team's season statistics, you first need to know how individual numbers like strike rate and booleans like 'isOut' are represented, the way TypeScript grounds primitives first.

2. Syntax

typescript
let str: string = "hello";
let num: number = 42;
let flag: boolean = true;
let big: bigint = 100n;
let sym: symbol = Symbol("id");
let u: undefined = undefined;
let n: null = null;

3. Explanation

3.1 string

The string type represents textual data, written with single quotes, double quotes, or backticks (template literals). It covers everything from single characters to entire documents.

🏏

Cricket analogy: A commentator's description of the pitch report, the player's name, or the ground's name are all string values in TypeScript, whether written as 'Lord's', "MCG", or a template literal like ` ${venue} Stadium `.

3.2 number

The number type represents all numeric values — integers, floating-point numbers, hex, octal, and binary literals all share the single number type.

🏏

Cricket analogy: A batter's strike rate, an over count, and a hexadecimal jersey-color code all share the single number type in TypeScript, whether written as 142.5, 20, or 0x1F.

Unlike languages such as Java or C++, TypeScript has no separate int, float, or double type. Every numeric value — whole or fractional — is typed as number, backed by JavaScript's IEEE 754 double-precision floating point representation. For integers beyond Number.MAX_SAFE_INTEGER, use the distinct bigint type instead.

3.3 boolean

The boolean type has exactly two values: true and false. It is commonly used for flags and conditional logic.

🏏

Cricket analogy: Whether a batter isOut has exactly two possible values, true or false, and umpires use this kind of flag constantly, just like TypeScript's boolean type for conditional decisions.

3.4 null, undefined, bigint, and symbol

undefined represents a variable that has been declared but not assigned a value; null represents an intentional absence of value. bigint represents arbitrarily large integers using the n suffix (e.g. 123n). symbol produces unique, immutable identifiers often used as object property keys.

🏏

Cricket analogy: A newly created but not-yet-filled 'manOfTheSeries' field is undefined, an abandoned match's result is deliberately null, a career run total might need bigint for astronomical aggregate stats, and a symbol could uniquely key a player's internal record.

By default, unless strictNullChecks is enabled in tsconfig.json, null and undefined are assignable to every type, silently defeating type safety. Always enable strict mode (which includes strictNullChecks) so that a string variable cannot accidentally hold null.

4. Example

typescript
let title: string = "TypeScript Basics";
let price: number = 19.99;
let quantity: number = 3;
let inStock: boolean = true;
let total: number = price * quantity;

console.log(`${title}: $${total.toFixed(2)}`);
console.log(`In stock: ${inStock}`);
console.log(typeof price, typeof quantity);

5. Output

text
TypeScript Basics: $59.97
In stock: true
number number

6. Key Takeaways

  • TypeScript's core primitives are string, number, and boolean.
  • There is only one numeric type, number — no separate int/float/double.
  • Use bigint (suffix n) for integers beyond the safe integer range.
  • null and undefined are distinct types that should be checked with strictNullChecks enabled.
  • symbol creates unique values, typically used as non-colliding object keys.
  • typeof at runtime reports "number" for every numeric value, integer or decimal.

Practice what you learned

Was this page helpful?

Topics covered

#TypeScript#TypeScriptProgrammingStudyNotes#Programming#PrimitiveTypesInTypeScript#Primitive#Types#Syntax#Explanation#StudyNotes#SkillVeris