Static vs Dynamic Typing: C vs JavaScript
Every number, string, or list has a type in a program. Programming languages split into two big groups when it comes to how they keep track of what type each value is. It's called static and dynamic typing, and it shapes how you write and debug code.
When a language is statically typed, it means every type must be known before your code even runs. In other words, type rules are checked during compile time, not at runtime. Dynamic typing flips that. Your program figures out the types as it runs, and lets you mix things up more freely.
Static Typing
Take C as the classic statically typed example. In C, you have to tell the compiler exactly what type each variable will hold, right when you declare it. The compiler doesn't let your code move forward if there’s a mismatch or you make a type mistake.
int age = 32;
char *name = "Pam Beesly";
float height = 5.4;
But if you try something like this:
int age = "thirty-two"; // Compile error: can't assign a string to an int
the compiler blocks you straight away. You have to be explicit and precise about types.
There are some strong upsides to this approach. You can catch silly mistakes and big bugs before you ever run the program. You won't pass a string to a function that wants a number without the compiler catching you. Your editor or IDE gives you deep auto-complete and code navigation, because it knows what you're working with, line by line and variable by variable. There’s a developer safety net.
Because types are always known up front, the compiler can also generate faster, more optimized code.
Of course, you have to write more boilerplate — every variable or function needs a type, and it can feel tedious at first. But this small cost pays off in terms of long-term stability and fewer debugging headaches.
With static typing, large teams or complex codebases benefit because everyone can trust what each piece of code is supposed to receive and return. There are fewer 'unexpected' bugs. Plus, refactoring is safer, because the compiler yells at you if you forgot something.
Dynamic Typing
Dynamic typing takes a completely different path. JavaScript is the poster child here. You just declare a variable and assign it whatever you want. The type gets tracked at runtime, not at compile time. If the type changes, the variable just goes along with it.
let age = 32; // age starts out as a number
age = "thirty-two"; // now age holds a string!
You won't see an error until (and unless) you try to do something the engine can't handle:
let age = 32;
console.log(age + 1); // 33
age = "thirty-two";
console.log(age + 1); // "thirty-two1" (string concatenation)
You write less upfront code since you don’t have to decorate everything with type annotations. This is handy when your data is flexible, or coming from user input or APIs you don’t control. It makes prototyping very fast, and you rarely feel blocked by the type system.
But the flexibility comes at a cost. If you pass the wrong thing around, you might not notice until users hit a weird case in production. Editors can't give you much help, since any variable could be anything. Lots of strange bugs creep in thanks to automatic type coercion, and some expressions like [] + {} can surprise even seasoned developers.
Some issues are only found when you actually run into them, which might be much later after the relevant line was written.
JavaScript tries to bridge this gap with TypeScript. TypeScript is basically JavaScript with static typing layered on top. You can choose when and where to declare types, or even leave most code as-is and gradually adopt more type-safety over time.
TypeScript's compiler scans your code before running it, pointing out type mismatches and helping you spot mistakes early. This gives you better editor completion, higher confidence when refactoring, and a little peace of mind even as your JavaScript codebase grows complex.
At the end of the day, static and dynamic typing serve different purposes and workflows. Static typing is about safety, structure, and clarity — dynamic typing is about speed, experimentation, and flexibility. Many modern projects actually combine both worlds: fast iteration with JavaScript, then growing structure and adding type safety through TypeScript as things get serious.