# JavaScript and TypeScript

> The one language every web browser runs, and TypeScript, which adds types to it. What it checks, and why it turns back into JavaScript.

**Course:** [Programming Languages](https://learn.benibix.com/learn/development-languages)  
**Time:** 12 min

**After this lesson you can:**

- Say why every web page uses JavaScript
- Explain what TypeScript adds
- Say what happens to TypeScript before it runs

## Why the web runs on JavaScript, and what TypeScript adds

JavaScript is the only language that every web browser runs on its own. It was made in 1995, for one of the first web browsers, to make pages react to clicks and typing. Today it does far more. Menus that open, forms that check what you typed, and maps you can drag are all JavaScript running in your browser.

JavaScript is not just for browsers any more. Tools like Node.js run it on servers too, so one language can build both halves of a web app. Its name is a leftover from 1990s marketing. It has almost nothing to do with Java.

JavaScript is dynamically and weakly typed. That makes small scripts quick to write. In a big app it lets mistakes slip through, such as passing text where a number was expected. The page still loads, and the bug shows up later, in a user's browser.

TypeScript is JavaScript with types added. Microsoft made it public in 2012. You write let count: number = 0, and the TypeScript tools check every use of count before the code runs. Pass it text and you see the error in your editor, not in a user's browser.

Browsers do not run TypeScript. So a build step strips the types out and leaves plain JavaScript. The types are only there to catch mistakes while you write. Every JavaScript file is already valid TypeScript. So a team can switch over one file at a time.

Which to learn? Start with JavaScript, because TypeScript is JavaScript plus types and you need the base first. Most large web teams now write TypeScript. A small script or a quick page is often fine in plain JavaScript.

The common mistake is thinking TypeScript makes the code run faster or safer for users. It changes nothing at run time, because the types are gone by then. It makes the code safer to write and to change.

```typescript
function total(price: number, qty: number): number {
  return price * qty;
}

total(2.5, 4);      // 10
total("2.5", 4);    // error before it runs:
// Argument of type 'string' is not assignable
// to parameter of type 'number'.
```
TypeScript spots the text in the second call while you type. Plain JavaScript would run it and give a wrong answer.

![Left to right: a TypeScript file with price: number, a type check step that catches a wrong call and marks it with an error, a build step that strips the types out, and a plain JavaScript file that a browser runs.](https://learn.benibix.com/diagrams/lang-js-ts.svg)

### Example: Lucy's team moves to TypeScript

Lucy's team has 300 JavaScript files. They rename 20 of the busiest to TypeScript first, and the type check finds 14 hidden bugs in a day.

Over 3 months they move the rest, one file at a time. The app keeps working the whole time, since old files are fine as they are.

**Words in this lesson:** [JavaScript](https://learn.benibix.com/term/development/javascript), [TypeScript](https://learn.benibix.com/term/development/typescript)

**Question:** What is done to TypeScript before a browser can run it?

**Answer:** The types are stripped and it becomes plain JavaScript. Browsers only run JavaScript. A build step removes the types, which have already done their job of catching mistakes.

---

Source: https://learn.benibix.com/learn/development-languages/javascript-and-typescript
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
