C# Strongly Typed & Dynamically Typed Language
- By Shiv Prasad Koirala in C#
- Dec 26th, 2022
- 1280
- 0
There are so many other programming languages which are strongly typed or statically typed one of the is our TypeScript language which is also known as super set of JavaScript language.
In strongly typed language every variable must have type and variable can receives only the values of its type. In TypeScript type identification can happen in compile time. As the named suggested that statically typed language we must necessary to declare the variable with its type before assigning the value to that particular variable.
Let's conclude with an example:
In the above example while I'm trying to insert the different type values in same variable. It shows the error in TypeScript like "subsequent variable declarations must have same type". it means we can not assign other type values to that variable which one we declared with another type. From above examples we get the clear idea.
So many programming languages have dynamically typed language JavaScript is one f them. In JavaScript variable have no types and also variable can change dynamically.
- JavaScript checks the variable type only at run time, but not at compile time. That's why it is called dynamically typed language.
- Hence, it is also called loosely typed language.
- So, in dynamically typed language there are chances type-related bugs.
- The following figure illustrates the example:
Let's take an example for understanding the same:
As you can see in the given example we declared the variable x without mentioning their datatype as number as 10 then again, we override the same variable with string datatype value as "bikesh". It also take the value because it checks the variable at run time so here it shows the dynamic behavior that's why it is called loosely typed/ dynamically typed language.
We will also see how these two languages differ from each other :-
Dynamically or Weakly typed | Strongly or Statically typed |
---|---|
Dynamically-typed language performs type checking at runtime. | Statically typed languages perform type checking at compile time. |
Type errors are detected later during execution. | Type errors are detected earlier. |
Variable assignments are dynamic and can be altered. | Variable assignments are static and cannot be changed. |
Produces less optimized code, run time error are possible. | Produces more optimized code. |
Examples: JavaScript, Ruby, PHP etc. | Examples: C, C++, C#, Java, TypeScript etc. |
More such technical concepts you can quickly go through from below 1 hour .NET C# Questions with answers video :-
Shiv Prasad Koirala
Visit us @ www.questpond.com or call us at 022-66752917... read more