JavaScript Core/
Lesson

Imagine writing a long email without spell-check. You hit send, and only then discover embarrassing typos. JavaScript is like that, it lets you write code with mistakes that only blow up when someone actually runs your app. TypeScript is like having a really smart editor watching your every keystroke, catching errors before they become bugs.

The problem with JavaScript's flexibility

JavaScript is dynamically typed, which sounds freeing until it isn't. The language lets you do almost anything, and it only complains when things actually break at runtimeWhat is runtime?The environment that runs your code after it's written. Some languages need a runtime installed on the machine; others (like Go) bake it into the binary..

// JavaScript happily accepts this disaster
function calculateTotal(price, quantity) {
  return price + quantity;
}

const result = calculateTotal('10', 5);
console.log(result);  // "105" - string concatenation, not math!

In this example, JavaScript sees you're adding a string and a number, so it helpfully converts the number to a string and concatenates them. The result? "105" instead of 50. Your app doesn't crash, it just produces wrong results silently.

02

How TypeScript catches errors early

TypeScript adds a compilation step where it analyzes your code before it runs. It checks that you're using values correctly, that you're not calling methods on undefined, that you're passing the right types to functions, that you're accessing properties that actually exist.

function calculateTotal(price: number, quantity: number): number {
  return price * quantity;
}

// Error: Argument of type 'string' is not assignable to parameter of type 'number'
const result = calculateTotal('10', 5);

The moment you try to pass a string where a number is expected, TypeScript underlines the problem in red. You fix it right then, not three weeks later when a customer reports weird totals.

03

The power of intelligent autocomplete

When TypeScript knows the shape of your data, it can suggest exactly what properties and methods are available. No more guessing whether it's response.json() or response.body or response.data.

interface User {
  name: string;
  email: string;
  age: number;
}

const user: User = { name: 'John', email: 'john@example.com', age: 30 };

// Your IDE shows name, email, age as autocomplete suggestions
user.name  // TypeScript knows this is a string
FeatureWithout TypeScriptWith TypeScript
AutocompleteGeneric suggestions based on textPrecise suggestions based on types
RefactoringFind-and-replace (risky)Rename symbol (safe across files)
DocumentationComments (often outdated)Types are living documentation
Error detectionRuntime crashesCompile-time warnings
04

How TypeScript actually works

TypeScript doesn't run in the browser. It's purely a development-time tool. You write TypeScript code, the compilerWhat is compiler?A program that translates code you write into a language your computer can execute. It also catches errors before your code runs. checks it for errors, then it strips away all the type annotations and outputs plain JavaScript.

// TypeScript code you write
interface Point { x: number; y: number; }
const p: Point = { x: 10, y: 20 };
console.log(p.x);
// Compiled JavaScript that actually runs
const p = { x: 10, y: 20 };
console.log(p.x);

The interface declaration and type annotationWhat is type annotation?Explicitly labeling a variable or function parameter with its type in TypeScript (e.g., name: string). completely disappear. Your runtimeWhat is runtime?The environment that runs your code after it's written. Some languages need a runtime installed on the machine; others (like Go) bake it into the binary. code is clean, standard JavaScript with zero performance cost.

StageWhat happensWhere types exist
DevelopmentYou write .ts files with typesIn your code
Compilationtsc checks types and emits .jsBeing checked
RuntimeBrowser/Node runs .js filesGone, zero overhead
05

Quick reference

ConceptDescription
Static typingErrors caught before code runs
Type erasureTypes removed at compile time, zero runtime cost
Type inferenceTypeScript guesses types from assigned values
AutocompleteIDE suggests properties/methods based on known types
Safe refactoringRename a symbol and every reference updates across files
AI pitfall, @ts-ignore everywhere. When AI tools like Copilot hit a type error, they sometimes add // @ts-ignore above the line to silence it. This doesn't fix the problem, it hides it. The bug is still there, waiting to crash at runtime. If you see @ts-ignore in generated code, delete the comment and fix the actual type mismatch instead.