Dev tools
TypeScript vs JavaScript: Differences and When to Switch
TypeScript vs JavaScript: TypeScript adds static types to JavaScript and compiles away. Syntax, performance, React use and which to learn, compared.
TypeScript vs JavaScript isn't a choice between two unrelated languages: TypeScript is JavaScript plus a type system. You write JavaScript with type annotations, a checker finds mistakes before the code runs, and the types are removed so that plain JavaScript is what actually executes in the browser or on the server. JavaScript is quicker to start and needs no build step; TypeScript catches whole categories of bugs early and makes large codebases easier to change, which is why most new professional projects now start in TypeScript.
This guide compares TypeScript vs JavaScript on syntax, performance, tooling, React and Node.js use, and learning, explains what changed recently (native TypeScript speed and Node.js running .ts files directly), and ends with clear advice on when to use which.
TypeScript vs JavaScript at a Glance
| JavaScript | TypeScript | |
|---|---|---|
| What it is | The language browsers and Node.js run | A typed superset of JavaScript that compiles to JavaScript |
| Typing | Dynamic: types are checked while the program runs | Static, optional: types are checked before the program runs |
| Build step | None needed | Needs type checking; type-stripping runtimes can run it directly |
| Runtime speed | Baseline | Same: types are erased, the output is JavaScript |
| Error detection | At runtime, or by tests | Many errors found in the editor and at compile time |
| Editor support | Good | Excellent: autocomplete, refactoring and navigation rely on types |
| Learning curve | Lower | Slightly higher: types, interfaces, generics |
| Best for | Small scripts, prototypes, learning the basics | Apps, libraries, teams and anything maintained long term |
| Created by | Brendan Eich at Netscape (1995), standardized as ECMAScript | Microsoft (2012), open source |
What Is JavaScript?
JavaScript is the programming language of the web. Every browser runs it, and Node.js, Deno and Bun run it on servers and in command-line tools. It's dynamically typed: a variable can hold a number now and a string later, and the language only finds out a value has the wrong type when the code actually runs. That flexibility makes JavaScript fast to write and forgiving for beginners, but it also means a typo in a property name or a missing argument can slip through until a user hits it.
What Is TypeScript?
TypeScript is an open-source language from Microsoft that adds static types to JavaScript. Any valid JavaScript is also valid TypeScript, and you add type information where it helps: function parameters, return values, object shapes. The TypeScript checker reads those annotations and reports mismatches, and a compiler (or a faster tool) strips them out to produce ordinary JavaScript.
TypeScript has grown from an option for large teams into the default for much of the industry. GitHub's Octoverse report found that in August 2025 TypeScript overtook both Python and JavaScript to become the most used language on GitHub, and noted that nearly every major frontend framework now scaffolds new projects with TypeScript by default.
TypeScript vs JavaScript Syntax
The typescript vs javascript syntax difference is small at the surface: TypeScript adds type annotations and a few type-only constructs. Here's the same function in both:
// JavaScript
function getTotal(items, taxRate) {
return items.reduce((sum, item) => sum + item.price * item.qty, 0) * (1 + taxRate);
}
getTotal([{ price: 10, qty: 2 }], "0.2"); // no warning; returns a wrong string-based result// TypeScript
interface LineItem {
price: number;
qty: number;
}
function getTotal(items: LineItem[], taxRate: number): number {
return items.reduce((sum, item) => sum + item.price * item.qty, 0) * (1 + taxRate);
}
getTotal([{ price: 10, qty: 2 }], "0.2"); // error: string is not assignable to numberIn JavaScript, passing "0.2" as a string produces a wrong result at runtime, because 1 + "0.2" becomes the string "10.2". TypeScript flags the call in the editor before you run anything.
The main TypeScript additions:
| Feature | Example | What it does |
|---|---|---|
| Type annotations | let count: number = 0 | Declares the expected type |
| Interfaces and type aliases | interface User { id: string } | Describe the shape of objects |
| Union types | `status: "open" \ | "closed"` |
| Generics | function first<T>(xs: T[]): T | Write reusable code that keeps type information |
| Optional properties | email?: string | Mark fields that may be missing |
| Type inference | const n = 5 (inferred as number) | Most types are worked out automatically |
| Enums | enum Role { Admin, User } | Named constants (a TypeScript-only construct that emits code) |
unknown and type narrowing | if (typeof x === "string") | Safely handle values of unknown type |
Because of type inference, real TypeScript code usually has fewer annotations than people expect. You mostly annotate function signatures and data shapes; the rest is inferred.
TypeScript vs JavaScript Performance
There's no runtime difference in typescript vs javascript performance, because TypeScript doesn't run: its types are erased and the result is JavaScript. A function written in TypeScript and the same function written in JavaScript produce the same code for the engine to execute. If anything, typed code can help indirectly, because consistent object shapes are easier for JavaScript engines to optimize, but that comes from how you write the code, not from TypeScript itself.
Where performance does differ is in development:
- Type checking takes time. In large projects, running the checker used to take tens of seconds or more. TypeScript 7, released on July 8, 2026, is a native port of the compiler written in Go, and Microsoft reports it's often about 10 times faster than TypeScript 6. The team chose Go for the port because its code could stay structurally close to the existing compiler.
- Build steps add a little friction. Bundlers such as Vite and esbuild strip types very quickly without checking them, so most projects run the full type check separately, in the editor and in CI.
Running TypeScript Without a Build Step
A big recent change is that you can often run TypeScript files directly. Node.js added "type stripping", which removes type annotations on the fly. It no longer shows an experimental warning from Node.js 22.18 and 24.3, and it became stable in Node.js 24.12 and 25.2. By default, Node.js runs .ts files that contain only "erasable" TypeScript syntax, meaning annotations that can be deleted without changing behavior.
node app.tsTypeScript features that generate code, such as enum declarations, namespaces with runtime code and constructor parameter properties, aren't erasable, so they need a real compile step (Node.js documents these limits). Many teams now avoid those features and use plain objects or union types instead. Deno and Bun run TypeScript directly too; our comparison of Bun vs Node covers how each handles it.
Type stripping doesn't check types. You still run tsc (or your editor) to find type errors; the runtime only skips the build.
TypeScript vs JavaScript for React
For new React projects, TypeScript is the common default. The typescript vs javascript for react question comes down to components and props: TypeScript lets you describe exactly what props a component accepts, so passing the wrong prop or forgetting a required one shows up in the editor.
type ButtonProps = {
label: string;
onClick: () => void;
disabled?: boolean;
};
export function Button({ label, onClick, disabled = false }: ButtonProps) {
return (
<button onClick={onClick} disabled={disabled}>
{label}
</button>
);
}React's popular starter templates and frameworks (Vite templates, Next.js and others) offer TypeScript from the first command, and most component libraries ship their own type definitions, so autocomplete works out of the box. Plain JavaScript React still works fine for small projects and tutorials.
Pros and Cons of TypeScript
Pros
- Catches typos, wrong arguments and missing null checks before the code runs.
- Makes refactoring safer: rename a field and the checker shows every place to update.
- Editor autocomplete and navigation are far better.
- Types act as documentation that can't go out of date.
- Works well with AI coding assistants, which produce more reliable code when types describe what's expected. GitHub's Octoverse report links TypeScript's rise to exactly this: typed languages make agent-assisted coding more reliable.
Cons
- More to learn: generics, utility types and advanced type features can get complex.
- Setup and configuration (
tsconfig.json), though modern tools hide most of it. - Type checking adds a step to your workflow and CI.
- Types are only checked at compile time; data coming from APIs or users still needs runtime validation (libraries such as Zod are popular for this).
- Some third-party JavaScript packages have incomplete or missing type definitions.
When JavaScript Is Still the Better Choice
TypeScript isn't always worth it. Plain JavaScript makes sense for:
- Small scripts, one-off tools and quick prototypes you'll throw away.
- Learning programming basics, where types are one more concept at once.
- Browser snippets and bookmarklets that run without any tooling.
- Projects where the team doesn't know TypeScript and the code won't grow.
Many teams also use JavaScript with JSDoc comments, which the TypeScript checker can read. That gives you a lot of type safety without changing file extensions or adding a build step.
Should I Learn TypeScript or JavaScript First?
If you're asking "should I learn TypeScript or JavaScript", learn JavaScript first, then move to TypeScript quickly. TypeScript is JavaScript plus types, so you need to understand the underlying language: variables, functions, objects, arrays, promises and async code. Once those make sense, usually after a few weeks to a couple of months of practice, start writing TypeScript; most developers become comfortable with everyday TypeScript within a few weeks.
If you already know a typed language such as Java, C# or Go, you can start directly with TypeScript and pick up JavaScript's quirks along the way. If you're choosing between a web language and Python for your first language, our guide to Python vs TypeScript compares the two paths.
How to Move a JavaScript Project to TypeScript
You don't have to convert everything at once:
- Add TypeScript as a dev dependency and create a
tsconfig.jsonwithallowJsturned on, so.jsand.tsfiles live side by side. - Turn on
checkJsor add// @ts-checkto important files to get type checking on existing JavaScript. - Rename files to
.tsone at a time, starting with shared utilities and data models. - Add types for your core data (API responses, database records) first; they pay off everywhere.
- Increase strictness gradually, ending with
"strict": true. - Run
tsc --noEmitin CI so type errors block merges.
Which Should You Choose?
| Situation | Choose |
|---|---|
| New web app, API or library you'll maintain | TypeScript |
| Team of more than one or two developers | TypeScript |
| React, Vue, Angular or Svelte project | TypeScript (Angular requires it) |
| Quick script, prototype or learning exercise | JavaScript |
| Existing JavaScript codebase that works well | Add types gradually with JSDoc or allowJs |
| Heavy use of AI coding assistants | TypeScript |
For most real projects, TypeScript is the better default. JavaScript remains the language underneath it, and knowing it well is what makes you good at TypeScript.
FAQ
Is TypeScript better than JavaScript?
For most applications that are maintained over time, yes: TypeScript catches errors earlier, makes refactoring safer and improves editor support. JavaScript is better for small scripts and prototypes where a type system adds overhead without much benefit.
Is TypeScript faster than JavaScript?
No. TypeScript compiles to JavaScript, and the types are removed, so the code that runs is the same. TypeScript only speeds up development by catching errors earlier; it doesn't change runtime performance.
Can browsers run TypeScript?
Not directly. Browsers run JavaScript, so TypeScript is compiled or type-stripped first, usually by a bundler such as Vite. On the server, Node.js, Deno and Bun can run TypeScript files directly by stripping types.
Do I need to know JavaScript to learn TypeScript?
Yes, mostly. TypeScript uses JavaScript's syntax and runtime behavior and only adds types on top. Understanding JavaScript basics first makes TypeScript much easier to learn.
How long does it take to learn TypeScript?
If you already know JavaScript, you can write everyday TypeScript within a few weeks: annotating functions, defining interfaces and using union types. Advanced type features such as conditional and mapped types take longer, but most projects use them sparingly.