TypeScript vs JavaScript, and which one to learn first
TypeScript is JavaScript with types that are checked while you write and removed before the code runs. Here's how the two differ, what TypeScript can't check, and why you should learn JavaScript first.

Picture moving house. You can pack everything into plain boxes, and it all arrives. Or you can label each box: "kitchen, plates, fragile". The movers know where each one goes and how to carry it before they lift it. Once you unpack, the plates are the same plates either way.
TypeScript is JavaScript with types added: labels that say what kind of value each name must hold, checked by the TypeScript compiler before your code runs and then removed, so the browser runs plain JavaScript. JavaScript finds a wrong value only while the code runs. TypeScript points at it while you write. Learn JavaScript first, then add TypeScript on top.
What's the difference between TypeScript and JavaScript?
TypeScript isn't a separate language that replaces JavaScript. Almost any JavaScript file is already valid TypeScript. What TypeScript adds is a way to write types, like price: number, and a compiler that checks your code against them. Here's how the two compare, row by row:
| JavaScript | TypeScript | |
|---|---|---|
| What it is | The language browsers and Node run | JavaScript plus types |
| What the browser runs | Your code, as you wrote it | Your code with the types removed |
| When a wrong type shows | While the code runs, maybe in front of a user | In your editor, before the code runs |
| File names | .js, and .jsx with JSX |
.ts, and .tsx with JSX |
| Setup | None | The compiler, tsc, and a tsconfig.json file of settings |
| Speed when it runs | The same | The same, because it's the same JavaScript |
Even if you never write a type, your editor may already use TypeScript: editors like VS Code ask it about your code all the time, even in plain .js files. Why TypeScript? shows what writing your own types adds on top of that.
What does the same bug look like in each?
A shop page adds up a cart. Tea costs 3 and cake costs 4, but the cake's price came from a form, and a form gives you text. In JavaScript:
const teaPrice = 3;
const cakePrice = "4";
console.log(teaPrice + cakePrice); // 34
When one side of + is text, JavaScript joins the two instead of adding them, so this prints 34 (the type conversion lesson explains why). Nothing warns you. The first person to notice might be a shopper looking at a total of $34.
Now the same code in TypeScript, with two types added:
const teaPrice: number = 3;
const cakePrice: number = "4";
// Error: Type 'string' is not assignable to type 'number'.
console.log(teaPrice + cakePrice);
Line 2 says cakePrice must be a number and then gives it text, so TypeScript marks it the moment you type it. You fix it with Number("4") or by passing 4, and the bug never reaches a shopper.

You don't have to write a type on every variable, either. TypeScript works out most types from the values, which is called inference. You write them mostly on function parameters and on data that comes from outside. Type annotations & inference shows where each one belongs.
What happens to TypeScript when the code runs?
Nothing, because there's no TypeScript left. The compiler does two jobs. It checks your types and reports errors, then it writes JavaScript with the types removed. Types never exist while the code runs, so a type can never change what your code does.
By default, an error doesn't stop the second job. tsc reports the error and still writes the JavaScript, bug and all. The --noEmitOnError option makes it write nothing when there's an error. How TypeScript works follows one file through both jobs.
Many tools only do the second job. Vite and Node remove the types from each file so it can run, and never check them. The checking is left to your editor, and to a tsc --noEmit run before you ship. Type checking vs type stripping shows how projects set that up.
There's one exception to "types are only removed". A few TypeScript features make real JavaScript. An enum, for example, becomes a JavaScript object. Enums shows what it compiles to, and the plain unions that often replace it.
What can't TypeScript check?
Because the types are gone when the code runs, TypeScript can't check anything that only exists at that moment:
- Data from a server.
response.json()can give back anything, so TypeScript trusts the type you write. A price sent as text still gets through. Typing fetch & JSON shows how to check a reply before you trust it. - Wrong logic with the right types. If you add a price and a quantity where you meant to multiply them, both are numbers, and TypeScript has nothing to say. Tests find that kind of mistake.
- Speed. The browser runs the same JavaScript either way, so TypeScript doesn't make your page faster.
Should you learn JavaScript or TypeScript first?
Learn JavaScript first. TypeScript adds to JavaScript and doesn't replace any of it. Every TypeScript error talks about JavaScript values: strings, objects, functions, and promises. If those are still new, you'd be learning two things at once, and the errors would be hard to read.
You don't need all of JavaScript before you start. Be comfortable with:
- values and their kinds, from data types to how they convert
- functions, objects, and arrays
- promises and
async/await - modules, with
importandexport
The JavaScript course covers all of them. Once they feel natural, TypeScript is a smaller step than it looks, because the code you write is still JavaScript. The TypeScript course is written for exactly that moment: it assumes you know JavaScript and teaches only what the types add.
Can you use both in the same project?
Yes, and that's how you move an existing project over without stopping work. A tsconfig.json with allowJs lets .js and .ts files import each other, so a team can rename one file at a time. Migrating JavaScript to TypeScript walks through it, step by step, without stopping the app.
You can even get type checking without leaving .js files. Write the types in JSDoc comments, like /** @param {number} price */, and put // @ts-check at the top of the file. The browser skips the comments and runs the file unchanged. Types in JavaScript files shows how, and it's a gentle first step if TypeScript still feels like a lot.
Where to go next
If you're still learning JavaScript, keep going with the JavaScript course, and come back when functions, objects, and promises feel easy. If you're ready for types, start the TypeScript course with Why TypeScript?. Still deciding whether it's worth the effort? Is TypeScript worth learning? weighs what it gives a frontend developer against what it costs.


