June 15, 2026โ€ข5 min read

Static Typing vs Dynamic Typing: What's the Difference?

Ever wondered why Java makes you declare a type while Python just takes the value? Here's the difference between static typing and dynamic typing.

Read in Indonesian

When we talk about programming, variables always come up. In how they get written, two camps dominate: static typing (statically typed) and dynamic typing (dynamically typed). So what's the difference, and which one fits your needs? Let's break it down! ๐Ÿ˜Ž

Key takeaways

  • Static typing checks types at compile time, which makes a program safer from type bugs.
  • Dynamic typing checks types at runtime, which makes writing code faster and more flexible.
  • The choice depends on project scale, performance needs, and what the developer prefers.

Static Typing

Static typing refers to languages whose data types can't change once they're set. That happens because every variable's type must be known at compile time. Before the program runs, the compiler checks all the types to make sure nothing is off.

A few languages that use static typing are C++, Go, Pascal, and Java. Let's look at the characteristics, the strengths, and the weaknesses!

Characteristics

The static typing style usually sticks to compiled languages. As a developer, you're required to declare the type explicitly when you create a variable. Once the type is set, it stays permanent and can't be swapped later.

For example, in Java:

JAVA
int angka = 90;       // variable of type int
String nama = "inva"; // variable of type String

In the Java code above, both angka and nama will hold those types forever. If you try to slip in a value of the wrong type, the compiler immediately yells about a type error. Like this:

JAVA
int angka = "satu"; // type error
String nama = 12;   // type error

Even though a type can't change directly, most languages still let you convert existing data into another type without changing the variable's own type. Usually that means type casting or parsing.

JAVA
double pecahan = 3.14d;
int bulat = (int) pecahan; // typecasting double to int

String stringAngka = "12";
int angka = Integer.parseInt(stringAngka); // parsing string to int

Relax, though, some statically typed languages are smart enough that you don't have to write the type on every line. They infer the type from the value you assign. The famous example is Go. Look at this syntax:

GO
var a int = 12 // int type declared explicitly
var b = 12     // int type inferred from the value
c := 12        // the shorthand version

Strengths

  • Fewer bugs: Compiler type checks up front save you from silly type mix-ups. When a type doesn't fit, the compiler tells you before the program runs.
  • Self-documented code: Types on every variable make code easier to read at a glance. You know exactly what a variable is for, so scaling the program goes smoother.
  • Better Developer Experience (DX): IDE features like code completion and auto-suggestion run at full power, because the IDE already knows the type of the object being typed.
  • Faster performance: Since the checks happened at compile time, the computer doesn't have to think about types at runtime. The result is a much faster app.

Weaknesses

  • Writing code feels slow: You have to spend extra time planning, writing, and tidying types. If you like moving fast, this can feel like drag on productivity.
  • Less flexible with data: Since a variable can't freely hold a different type, you sometimes need extra steps, like manual conversion, to process the data.

Dynamic Typing

While static typing shows up in compiled languages, dynamic typing is usually the default for interpreted languages. This style frees you to create variables without thinking about type declarations first.

Languages that use dynamic typing include Python, JavaScript, Ruby, PHP, and Perl. Let's look at the characteristics and the trade-offs! ๐Ÿš€

Characteristics

The reverse of static typing: you create variables without writing the type by hand. The interpreter detects and assigns the type automatically while the program runs (runtime).

A simple example in Python:

PYTHON
angka = 90    # variable is automatically an int
nama = "inva" # variable is automatically a string

Better yet, a variable's contents can change type whenever needed. The interpreter updates the type as soon as you assign a new value.

In the dynamic typing world, two implementation styles shape how a language handles data: strongly typed and weakly typed.

Strongly typed languages won't let you run operations between two different types without a manual conversion. Try it and the program throws an error. Examples are Python and Ruby:

PYTHON
a = 1 + "satu"      # This one throws an error here!
b = str(1) + "satu" # Must be converted manually first

Weakly typed languages are more relaxed and allow direct operations between two different types. The system converts the type behind the scenes. Examples are JavaScript and PHP:

JAVASCRIPT
let a = 1 + "satu"; // The result is '1satu'
let b = true && []; // The result is []
let c = !![];       // The result is true (headache starting yet? hehe)

Strengths

  • Much faster to write: With no type on every variable, you can focus fully on program logic. Code feels shorter and quicker to produce.
  • More flexible logic: A variable that changes type lets you reuse it for data in different formats. Still, avoid the trick unless you want confusing code!

Weaknesses

  • Prone to runtime errors: With no early compile step to filter wrong types, a type error is more likely to surface while the program runs on a server or a user's phone.
  • Harder to read as a project grows: Missing type information gets confusing when you read old code. You end up naming variables very carefully or writing docs to stay sane.
  • Slower execution: The computer has to keep detecting and matching types while the program runs. That's why dynamic languages usually aren't as fast as static ones.

In Short...

So the core difference comes down to when the types get checked:

  1. Static typing (Static): You must register the type when creating a variable, and the check happens before the program runs (compile time).
  2. Dynamic typing (Dynamic): You write code with no type declarations, and the check happens when the program executes (runtime).

So which do you prefer, static or dynamic languages? Why? Share your story in the comments!

Happy coding ๐Ÿ‘‹

Get better at shipping code.

Join the other developers getting tech updates, tips, and relaxed tutorials in their inbox every week.

Stay in the loop

Tech updates, coding tips, and relaxed insights straight to your inbox every week.

No spam. Unsubscribe anytime.

Read next

See all

For developers who learn by struggling

ยฉ 2026 Inva.dev.