Static vs. Dynamic Typing
Programming languages handle data types (Numbers, Strings, Objects) in two main ways.
Dynamic Typing (JavaScript, Python, PHP)
You don't need to define types. The computer figures it out while the code runs.
let x = 5; // x is a Number
x = "Hello"; // Now x is a String (This is allowed)
Pros: Fast to write. Less code. Flexible.
Cons: You find bugs at runtime (when the user is using the app). "undefined is not a function" is a common error.
Static Typing (Java, C++, TypeScript, Rust)
You must define types (or they are inferred) before running.
code
TypeScript
let x: number = 5;
x = "Hello"; // ERROR! The compiler stops you immediately.
Pros: You find bugs at compile time (while coding). Better autocomplete in editors. Safer for large teams.
Cons: More verbose. Takes longer to set up.
The Trend
The industry is moving toward Static Typing. The rise of TypeScript (Static) over plain JavaScript (Dynamic) shows that developers prefer safety for large projects.