TypeScript
A version of JavaScript with type labels that catches typos and mismatched values before your website ever goes live.
On this page
What is TypeScript?
TypeScript is a programming language built on JavaScript that adds type checking. You label whether each piece of data should be text, a number, or a list. If you put the wrong kind of thing in or misspell a name, your editor underlines the mistake right away instead of waiting for the website to break.
Think of labeling every pocket in your school bag: a bottle pocket for water only, and a pencil case for pens only. If you try to shove a notebook into the bottle pocket, you catch the mistake before you even walk out the door.
TypeScript does not teach browsers new tricks; it is a safety inspector that catches easy mistakes before your site goes live.
How does TypeScript code actually run?
From writing code to running in a browser, TypeScript adds one quick check-and-strip step.
Add type labels: mark whether a value is text (
string), a number (number), or true/false (boolean).Check as you type: your editor and compiler scan every place that value is used and flag typos or mismatches immediately.
Strip labels into JavaScript: once everything passes, the build tool erases the type labels and outputs plain JavaScript.
Run in the browser or Node.js: visitors’ browsers run that clean JavaScript just like any other website.
Because the type labels disappear before launch, TypeScript does not slow down your finished website.
Look at a tiny example
This small function congratulates a kid for earning stars, using type labels to make sure the name is text and the star count is a number.
name: stringmeans the name must be text;stars: numbermeans the star count must be a number.- If you accidentally write
greet('Mia', 'five'), the editor underlines it right away instead of waiting for someone to open the page. - Before the code reaches the browser, the build tool removes
: stringand: number, leaving plain JavaScript.
No need to memorize the syntax—just notice the string and number labels after the colons:
function greet(name: string, stars: number) {
return `${name} earned ${stars} stars!`;
}
greet('Mia', 5);Those two tiny labels stop both you and an AI assistant from accidentally mixing up text and numbers.
How is TypeScript different from JavaScript?
They are the same bicycle: JavaScript rides bare, while TypeScript adds training wheels and a bell.
| Compare | TypeScript | JavaScript |
|---|---|---|
| When mistakes show up | While you write code or before the site builds | Often not until a visitor clicks a button and something breaks |
| Editor and AI guidance | Every value has a clear label, so autocomplete and AI edits stay accurate | Fewer clues, making it easier to guess the wrong field name in bigger projects |
| Running in a browser | Needs a quick build step to turn into JavaScript first | Browsers can run it directly as-is |
Plain JavaScript is quick for tiny scripts. Once a project grows past a few files—or you rely on AI to edit it—TypeScript saves a lot of headaches.
When is TypeScript a good fit?
Most modern websites and AI-assisted projects pick TypeScript by default.
- Growing websites like portfolios and directories: rename one field and TypeScript highlights every file that needs an update.
- Coding with AI: clear types act like a blueprint, so AI tools make fewer guesses and break fewer pages.
- Working with others or coming back months later: hover over any value to see exactly what is inside without memorizing everything.
Catches typos and missing fields early so changing code feels much safer.
Requires writing a few extra labels and running a build step; for a quick ten-line experiment, plain JavaScript is lighter.
Common things people get wrong
Can web browsers run TypeScript directly?
No. Browsers run JavaScript. Frameworks like Next.js automatically strip the TypeScript labels behind the scenes, so you rarely notice the extra step.
Do I have to forget JavaScript and learn a brand-new language?
No. TypeScript wraps around JavaScript—almost everything you already know stays the same, plus a way to label your data.
Does TypeScript guarantee zero bugs?
No. It stops mix-ups like passing text where a number belongs, but it cannot tell if you wrote subtraction instead of addition or typed the wrong image URL.
Quick quiz
If TypeScript says a score must be a number and you accidentally pass text instead, when do you find out?
While writing code or before publishing. The editor and type checker flag the mismatch right away, long before any visitor opens the page.
Remember this: TypeScript is JavaScript with type labels that catch simple mistakes before your site goes live.
Read further
Explore these official guides if you want to dig deeper.