Strongly Typed vs, Weakly Typed Languages

Strongly typed, or statically typed, and weakly typed, or dynamically typed, languages refer to the syntax written when initialising and declaring variables and their data types. This means that in strongly typed languages we have to specify what data type a variable is (e.g. integer, string, etc) and what data type a function returns. This also means that when defining a variable of type integer it can only be an integer whereas when using a weakly typed language a variable type may be changed from an integer to a string without using a secondary variable.

The below code is written in a strongly typed language. We must define what type of variable is when declaring it, such as an integer or a string. This values must stick to the data type defined. This means that the variable ‘a’ can only be an integer throughout the entire program’s code.

The below code is written in a dynamically typed, or weakly typed, language. This means we do not specify what data type a variable is, and we don’t need to define the data type of function return values either. The below code shows that we can take a variable ‘a’ and assign it a string value and then change the data type and assign it to an integer value.

Leave a Reply