TypeScript vs JavaScript
Typed superset vs dynamic scripting language
TypeScript and JavaScript are closely related: TypeScript is a strict superset of JavaScript that adds optional static typing and compiles down to plain JavaScript. Every valid JavaScript program is also valid TypeScript, but TypeScript adds type annotations, interfaces, and compile-time checks that catch errors before code runs.
TypeScript
TypeScript is a statically typed superset of JavaScript developed by Microsoft and released in 2012. It adds type annotations, interfaces, enums, generics, and other features that enable better tooling, refactoring, and error detection at compile time. TypeScript code compiles (transpiles) to standard JavaScript that runs anywhere JavaScript runs. Adoption has grown rapidly, with most major frameworks (Angular, Next.js, Deno) and many libraries now written in TypeScript.
JavaScript
JavaScript is a dynamically typed scripting language created by Brendan Eich in 1995. Originally designed for simple browser interactivity, it has evolved into one of the most widely used programming languages in the world, running in browsers, servers (Node.js), mobile apps, and embedded systems. JavaScript is the only language natively supported by web browsers and is the foundation of the web platform.
Key Differences
- **Type system**: TypeScript has optional static types checked at compile time. JavaScript is dynamically typed with type checking only at runtime. - **Error detection**: TypeScript catches type errors, typos, and interface mismatches before the code runs. JavaScript surfaces these errors at runtime. - **Tooling**: TypeScript enables superior IDE support (autocompletion, refactoring, inline documentation). JavaScript tooling is good but less precise. - **Compilation**: TypeScript requires a build step to compile to JavaScript. JavaScript runs directly in browsers and Node.js. - **Learning curve**: JavaScript is simpler to start with. TypeScript adds concepts like generics, type inference, and declaration files. - **Compatibility**: All JavaScript is valid TypeScript. TypeScript code must be compiled before it can run as JavaScript.
When to Use Each
**Use TypeScript** for medium-to-large codebases where type safety prevents costly bugs, team projects where interfaces serve as documentation, projects using frameworks that embrace TypeScript (Angular, Next.js), or any codebase that will be maintained long-term. **Use JavaScript** for small scripts and prototypes where type overhead is not worth it, learning programming (start with JS, add TS later), browser console experiments and quick automation, or projects with tooling constraints that make TypeScript impractical.
Analogy
**JavaScript** is like writing with a pen: fast, direct, and flexible, but you only discover spelling mistakes when someone reads the final copy. **TypeScript** is like writing in a word processor with spell-check and grammar-check turned on: it adds a bit of friction, but catches mistakes as you type.