Static Typing vs Dynamic Typing — What's the Difference?
Static typing checks variable types at compile time, before the program runs; dynamic typing checks types at runtime, as the code actually executes.
Published November 23, 2026
Static typing checks types at compile time before the program runs (Java, Go, TypeScript); dynamic typing checks them at runtime (Python, JavaScript, Ruby). Static catches many bugs early, dynamic is more flexible and quicker to prototype.
The concept
In a static language a variable has a declared or inferred type and mismatches are compile errors. In a dynamic language, values carry types and a variable can hold anything.
Many dynamic languages now offer optional static checking (Python type hints, TypeScript).
When errors appear
Practical examples
Static (TypeScript)
function double(n: number) { return n * 2 }
double('4') // error at build timeDynamic (JavaScript)
function double(n) { return n * 2 }
double('4') // 8 (coerced) – no warningType inference
x := 42 // compiler infers intCommon mistakes
- Believing dynamic languages cannot be safe — add tests and types.
- Over-annotating when inference works.
- Ignoring runtime validation of external data even in static languages.
Key takeaways
- Static = checked before running.
- Dynamic = checked while running.
- Gradual typing mixes both.
FAQ
Which is faster?
Static languages can optimise more, though runtimes vary.
Which is better for large projects?
Static typing often helps maintain big codebases.