JavaScript
The language of the web, dynamically typed and run by browsers and Node.js.
Flexible and universal; type errors surface only at runtime.
Frontend
TypeScript is JavaScript with a static type system; the types are checked while you write and build, then erased, so the code that runs is plain JavaScript.
The language of the web, dynamically typed and run by browsers and Node.js.
Flexible and universal; type errors surface only at runtime.
A typed superset of JavaScript that compiles to JavaScript.
Interfaces, generics, narrowing and editor tooling catch bugs early and make large codebases safer to change.
| Aspect | JavaScript | TypeScript |
|---|---|---|
| Typing | Dynamic | Static (checked at build) |
| Runs directly | Yes | After compiling or type stripping |
| Errors found | At runtime | In the editor and build |
| Learning curve | Lower | Higher |
| Best for | Scripts, quick prototypes | Teams and large apps |
TypeScript is JavaScript plus a static type system. You annotate or infer types, the compiler checks them while you write and build, and then the types are erased so the code that runs is plain JavaScript.
Not directly. TypeScript is compiled or type-stripped to JavaScript by tsc, a bundler or a runtime with type stripping; browsers and Node.js run the resulting JavaScript.
No. Types are erased during compilation, so they cannot validate data arriving from APIs or users at runtime. Use a schema library such as Zod to validate untrusted input and infer types from it.
It catches whole classes of bugs before running code, documents function contracts, powers editor autocomplete and safe refactoring, and makes large codebases easier for many people to change.
Syntactically, yes, TypeScript is a superset; but the type checker may report errors in valid JavaScript, such as using a possibly undefined value, until you add types or adjust settings.
TypeScript works out types from values and return statements, so const count = 3 is a number without an annotation. You annotate mainly at boundaries such as function parameters and exported APIs.
Enabling strict turns on checks such as strictNullChecks and noImplicitAny, so null and undefined must be handled and untyped values are flagged. New projects should start strict.
any switches off type checking for a value, letting anything through. unknown accepts any value but forces you to narrow it with checks before using it, so it is the safe choice for untrusted data.
Both describe object shapes. Interfaces can be extended and merged by redeclaration; type aliases can also describe unions, intersections and mapped types. For most object shapes either works.
Generics let functions and types work with many types while keeping them linked, such as a function returning the same type it receives. JavaScript has no static types, so there is nothing to parameterise.
Practise every comparison in your dashboard.
Start learning