Dynamic Typing
Dynamic typing is a language design approach in which variable types are determined and checked at runtime rather than at compile time, so the same variable can hold different types of values over its lifetime.
Definition
Dynamic typing is a language design approach in which variable types are determined and checked at runtime rather than at compile time, so the same variable can hold different types of values over its lifetime.
Overview
In a dynamically typed language such as Python, JavaScript, Ruby, or PHP, a variable is simply a name bound to a value, and that value carries its own type — the variable itself has no fixed type declaration. Because there is no compile-time type check, code can be written and run immediately without annotating every parameter and return value, which makes dynamic languages popular for scripting, prototyping, and situations where iteration speed matters more than upfront verification. The cost of this flexibility is that certain type errors — such as calling a method that does not exist on the actual runtime value, or adding a number to a string in an unintended way — are only discovered when that specific line of code actually executes, which may be well after the bug was introduced and only in production if test coverage does not exercise that path. This is the opposite trade-off from static typing, which catches such errors at compile time at the cost of more upfront annotation. Many dynamically typed languages have responded to this gap by adding optional static checking on top: Python's type hints checked by tools like mypy, and TypeScript as a statically typed superset of JavaScript, let teams keep the flexibility of dynamic typing during early development while adding verification as a codebase matures and stability becomes more important than raw iteration speed.
Key Concepts
- Variable types are determined and checked at runtime, not compile time
- The same variable can hold values of different types over its lifetime
- No mandatory type annotations, enabling fast, low-ceremony coding
- Type errors surface only when the affected code path actually executes
- Common in Python, JavaScript, Ruby, and PHP
- Favors iteration speed and flexibility over compile-time safety
- Often paired with optional static checking tools like mypy or TypeScript