Sobes.tech
Junior — Middle

What is the difference between static and dynamic typing in programming languages?

sobes.tech AI

Answer from AI

Static typing is when the types of variables and expressions are checked at compile time. This means that type errors are detected before the program runs. Examples of statically typed languages: C, Java, Go.

Dynamic typing is when types are checked at runtime. Variables can change types, and type errors are only detected during execution. Examples: Python, JavaScript.

Example in Python (dynamic typing):

x = 5       # x is an integer
x = 'text'  # now x is a string

In statically typed languages, such changes are not allowed without explicit conversion.

The main difference is when and how type checking occurs, which affects code safety, flexibility, and performance.