Back to the Basics: Dynamic vs Static Typing

Last Modified
Last updated December 1, 2022
There’s a war between Dynamic and Static type supporters 🙂
var a = 100; // JS - Dynamic Type int a; // C++ - Static Type a = 100;
Dynamic languages type-check during runtime (JIT compilation).

Pros - Static Types

  • Self-documenting
  • Text editors/IDEs have stronger autocompletion when they know the types
  • Less bugs in production - because you catch bugs earlier (at compile time, in the editor, etc)

Pros - Dynamic Types

Cons - Static Types

  • Complexity/ramp-up
  • Can’t you write better tests? Static types might introduce laziness in writing unit tests
  • Slower development
  • Flexibility
  • Speed

Strong vs Weak Typing

var a = "booya"; a + 17 // "booya17";
Weakly typed languages make assumptions with type coercion
var = "booya" var + 17 # error
Strongly typed languages throw an error when they encounter the same mixing of typing

Typescript - Static Typing in JavaScript