#5) Is JavaScript a statically typed or Dynamically typed language🤔

Yes, JavaScript is a dynamically typed language.

🚀Static Typed Languages

In the above example,👆
We declare a variable name of string type by adding a prefix 'String' means it's value will always be of a string type.

But as we are going to re-assign the value of the variable name to some other data type which was earlier string, it will throw an error message and this only happens in statically typed language like TypeScript.

🚀Dynamic Typed Language

In the above example,👆
We assign a value to the variable 'x' without defining it's type.
So, the type of the variable is set dynamically depending on the value that we assigned to the variable.

In the next step, we re-assigned the value of the variable 'x' to a number type.
So, there will be no error because the type of the variable is set dynamically during code execution.

✔JavaScript is a dynamically typed language so you are free to re-assign value of any type by using either let or var.
image

Note:

âś…It's totally the developers responsibility to take care of the variables type and on a safer side use const.

âś…In dynamically typed language, the type of a variable is checked during run-time whereas...
In statically typed language, the type of a variable is checked during compile-time.

16