Statically typed

The type of every expression in a program is known at compile time, and the compiler can validate that the methods and fields we’re trying to access exist on objects we’re using. Examples: Java, Kotlin, C, C++,…

Type inference: the ability of the compiler to determine types from the context (e.g.: OCaml, Haskell, Scala, Kotlin). Type of variable is automatically determined from the context, allowing you to omit the type deceleration.

Code example:
Java: String str = “”;
Kotlin: val str = “”

Benefits of static typing:
Performance: calling methods is faster because there’s no need to figure out at runtime which method needs to be called
Reliability: compiler verifies the correctness of the program, so there are fewer chances for crashes at runtime
Maintainability: working with unfamiliar code is easier because you can see what kind of objects the code is working with

Dynamically typed

These languages let us define variables and functions that can store or return data of any type and resolve the method and filed reference at runtime. Examples: PHP, JavaScript, Python

Code example:
PHP: $name = ‘MyName’;
Python: name= “MyName”

Benefits of dynamic typing:
Shorter code and greater flexibility in creating data structures.