Why JavaScript is known as a Dynamically Typed Language?

Statically Vs Dynamically Typed Language

Dynamically-typed languages are those where the interpreter assigns variables a type at runtime based on the variable's value at the time.

In languages like C++ and Java, We need to specify the type of a variable before assigning it to a value, and once the variable is declared with a particular type we can not assign a value with another datatype to the same variable. The type of variable is checked during compile time. So, these languages are known as Statically Types Languages.

In the case of JavaScript, We do not need to specify the type when we declare a variable. The type of variable will be dependent on the value which we will assign to it. The type of variable is checked only during the runtime.

let a = 5; //type of a is number
a = "Code"; //type of a is String
a = {
    key : "value";
} // type of a is object

At runtime, the data type of the variable is changed if we assign a value with another datatype to the same variable.

In JS, "Value has a type, not a Variable!"