Home › Compare › JavaScript vs TypeScript

JavaScript vs TypeScript

From WikiTech, the encyclopedia of technology

The scripting language of the web versus its statically typed superset.

Overview

JavaScript is the language that browsers execute natively. TypeScript, announced by Microsoft in 2012, is a superset of JavaScript that adds a static type system and compiles back to plain JavaScript. Every valid JavaScript program is also a valid TypeScript program, which allows gradual adoption.

Because types are erased during compilation, TypeScript adds no runtime behaviour of its own. Its value lies in catching mistakes before the code runs and in giving editors accurate autocompletion and refactoring.

Side-by-side comparison

JavaScriptTypeScript
TypingDynamic, weak coercion rulesStatic, structural, with inference
Runs in browsersDirectlyAfter compilation to JavaScript
Error detectionAt run timeMany errors at compile time
Build stepOptionalRequired (compile or strip types)
GovernanceECMAScript, TC39 committeeDeveloped by Microsoft as open source
First release19952012

Choosing between them

JavaScript suits small scripts, quick experiments and projects where a build step is unwelcome. TypeScript tends to pay off in larger codebases and teams, where type annotations act as checked documentation and make refactoring safer.

Choosing TypeScript does not mean leaving the JavaScript ecosystem: type definitions exist for most popular libraries, and the two languages can live side by side in one project.

Read more

  • JavaScript: The programming language that powers interactive web pages and a large ecosystem of browser, server and desktop software.
  • TypeScript: A language that extends JavaScript with a static type system and compiles to ordinary JavaScript.