TypeScript
/Beginner
TypeScript vs JavaScript
Definition
JavaScript is a dynamically typed, interpreted language. TypeScript is a statically typed, compiled superset of JavaScript.
Explain Like I'm New
JavaScript waits until you run the car into a wall to tell you the brakes don't work (Runtime errors). TypeScript forces a mechanic to inspect the car before you are even allowed to turn the key (Compile-time errors).
Real World Example
Migrating a legacy React JS app to TS. Suddenly, hundreds of hidden bugs are exposed because components were secretly passing strings to props that expected arrays.
Common Use Cases
- •Choosing the right tool for a new project
Terminal Output
bash / terminal
// JavaScript: Dynamic typing (Types can change at runtime)
let data = 10;
data = "Hello"; // Perfectly fine in JS
// TypeScript: Static typing (Types are locked in)
let tsData: number = 10;
// tsData = "Hello"; // Error: Type 'string' is not assignable to type 'number'
Interview Questions
basic
- Does TypeScript make my website run faster?
intermediate
- What is the main drawback of using TypeScript?
advanced
- Does TypeScript guarantee zero runtime errors?