TypeScript Primitives

Anonymous contributor's avatar
Anonymous contributor
Published Aug 23, 2021Updated Oct 8, 2021
Contribute to Docs

TypeScript supports primitives, which are the basic types in JavaScript that make up data other than functions and objects. TypeScript recognizes the following seven primitive types in JavaScript:

  • bigint
  • boolean
  • null
  • number
  • string
  • symbol
  • undefined

If a value such as a parameter or variable is declared to be one of these, it is allowed to be assigned any of the literal values that are of that primitive type.

In this example, the variable decoration is initially declared to be type string. This means that decoration is allowed to be assigned, and reassigned, a plethora of string values:

let decoration: string;
decoration = 'Cobweb';
decoration = "Jack O'Lantern";
decoration = 'Lights';

In other words:

  • A primitive is a basic type of data, such as number or string
  • A literal is an example of a primitive with a value, such as 1337 or "ghost"
  • A full-stack engineer can get a project done from start to finish, back-end to front-end.
    • Includes 51 Courses
    • With Professional Certification
    • Beginner Friendly.
      150 hours
  • Learn TypeScript, a superset of JavaScript that adds types to make the language scale!
    • Intermediate.
      10 hours

All contributors

Contribute to Docs

Learn TypeScript on Codecademy

  • A full-stack engineer can get a project done from start to finish, back-end to front-end.
    • Includes 51 Courses
    • With Professional Certification
    • Beginner Friendly.
      150 hours
  • Learn TypeScript, a superset of JavaScript that adds types to make the language scale!
    • Intermediate.
      10 hours