Static typing vs Dynamic typing

Static Typing

For some programming languages like C, C++, and Java you need to specify the variable type while declaring it. This form of typing is called static typing. In this case, the value of the variable is determined at compile time itself by the compiler which helps in reducing the errors.

Thus these languages require more lines of code compared to the dynamically typed languages. But this feature also gives more power to us by avoiding a major part of the error at compile time itself.

int a=10; a="human"; this code will give an error in statically typed languages.

Dynamic Typing

In some programming languages like JavaScript, Python, Groovy and all we don't need to specify the variable type while declaring it. This form of typing is called Dynamic typing. In this case, the value of the variable is determined at runtime i.e. that is the type checking of variables is done while the program starts running.

You don't need to worry about what variable type you need to give in the se kinds of programming languages. It provides great flexibility but also causes some errors.

var a = 10; var b = "human"; This code will run just fine.

Note : var a=10; a="human" will not give you an error in dynamically typed programming languages.