Skip to main content

What does "static typing" mean?

Static typing means that the data type of a variable, parameter, or expression is checked at compile time, before the program runs.

In simpler terms, TypeScript (or another statically typed language) "checks types ahead of time", not while the code is running.


1. Example without static typing (JavaScript)

javascript
let name = "Alice"; name = 123; // allowed, JS does not check types console.log(name.toUpperCase()); // Runtime error

In JavaScript the error appears only when the program runs, because the type of name is not fixed.


2. Example with static typing (TypeScript)

javascript
let name: string = "Alice"; name = 123; // Compile error: string expected

TypeScript reports the error before the code even runs, preventing bugs in advance. The compiler simply will not let you build a project with such a type mismatch.


3. The main idea

With static typing:

  • types are known ahead of time (at compile time);
  • type errors are caught before the program runs;
  • the IDE and compiler can provide hints, autocomplete, and navigation.

4. The opposite: dynamic typing

ApproachWhen types are checkedExample languagesExample error
Static typingat compile timeTypeScript, Java, C#Error: "expected string, got number"
Dynamic typingat runtimeJavaScript, PythonError while the program runs

5. Advantages of static typing

  • Early error detection
  • Convenient IDE hints
  • Better readability and predictability of code
  • Safe refactoring and scaling of the project

In short:

Static typing is a mechanism that guarantees type correctness before the program runs, helping avoid many errors already at the development stage.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.