TypeScript · Types that pay for themselves

How does TypeScript differ from JavaScript?

EasytypescriptjavascriptcomparisonUpdated Oct 2026
Quiz this track

Short answer

JavaScript is dynamically typed and runs directly. TypeScript adds a static type layer, compiles to JavaScript and catches type errors before runtime, at the cost of a build step and ongoing type maintenance.

Both languages share the same runtime semantics: objects, prototypes, closures and the event loop behave identically. TypeScript is a superset, so valid JavaScript is generally valid TypeScript once the compiler can infer or check the types. The difference is when errors are discovered and how much structure the tooling can reason about.

ts
function add(a: number, b: number): number {
  return a + b;
}

const total = add(2, 3);

const wrong = add("2", 3);
The final call fails type checking. Plain JavaScript would run it and produce the string "23".

Trade-offs

  • JavaScript has no build step and no type annotations to maintain
  • TypeScript catches many errors before execution and improves refactoring
  • TypeScript needs a compiler or bundler step and a tsconfig
  • Type definitions must be kept accurate, especially at package boundaries
  • Both share the same runtime behavior and ecosystem

TypeScript is not a stricter runtime. It does not stop a value from being the wrong shape when it comes from JSON or a network response. It moves a class of mistakes earlier and gives editors a precise model of the code, but it cannot replace tests or validation.

Avoid treating TypeScript as a reason to skip runtime checks. Use it for the code you control and validation for data you do not control.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Is all JavaScript valid TypeScript?
  2. 2What costs does TypeScript add to a project?
  3. 3Does TypeScript change how the code runs?
  4. 4When would plain JavaScript be a better choice?

Say it in the interview

JavaScript runs directly and checks types at runtime. TypeScript adds a static type layer and compiles to JavaScript, so errors like passing a string where a number is expected show up in the editor or build. The trade-off is a build step and keeping types accurate. I reach for TypeScript on anything that will be maintained by a team or has non-trivial data shapes.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live TypeScript mock interview and get scored feedback on depth, clarity and confidence.