Course contentsShow
TypeScript
Lesson 1 of 1,7961. Why TypeScriptFree lesson

What is Static Typing?

Understanding the difference between static and dynamic type systems and when types are checked.

What is Static Typing?

You'll learn: The fundamental difference between static and dynamic typing, and why TypeScript checks types before your code runs.

The Core Idea

Imagine two different restaurants. In Restaurant A (static typing), the chef checks all ingredients before cooking starts — if you ordered chicken but they only have beef, they tell you immediately. In Restaurant B (dynamic typing), the chef starts cooking and only discovers the problem when they reach for the chicken that isn't there.

Static typing means your code's types are checked before the program runs. Dynamic typing means types are checked while the program is running.

When Types Are Checked

In statically typed languages like TypeScript:

  • Types are verified during a "compilation" or "checking" phase
  • Errors are caught before you ever run the code
  • You find out about type mismatches immediately in your editor

In dynamically typed languages like JavaScript:

  • Types are checked as the code executes
  • Errors only appear when that specific line runs
  • A type error might hide until a user clicks a rarely-used button

Why This Matters

Static typing catches mistakes early. If you write code that tries to use a number as if it were text, TypeScript tells you right away with a red squiggly line. JavaScript would let you run the code, and you'd only discover the problem when that code path executes — maybe in production, maybe never.

Think of it like spell-check in a document. Static typing is like spell-check that underlines mistakes as you type. Dynamic typing is like only discovering typos when someone reads your printed document aloud.

Key Takeaway: Static typing checks your types before code runs, catching errors early; dynamic typing checks types during execution, catching errors later (or not at all).