Ankaj Gupta
March 16, 2019
Define dynamic typing in JavaScript

Javascript Dynamic Typing

JavaScript is a dynamically data typed language, this means that type checking is done at runtime rather than compile time.

Dynamic Typing means that, define a data-type of a variable does't need to be specified, any variable can be used to hold any/different data types. They can easily change from one data type to another data type.

  • For instance : Ruby, Python, JavaScript etc.

Let's see an example of Dynamic Typing in JavaScript :

 ➤ Example :

    In this example, the variable myName change from string to number and then boolean.

<script>
  let myName = 'Ankaj Gupta';  //Ankaj Gupta
  myName = 100;  //100 
  myName = true;  //true
</script>
Example explained :
  • In this example, the variable myName, defined as a variable by the let keyword, can be assigned to hold different data types, or can be initialized.

  • Each of the variables myName above can be set to any data type available in JavaScript. They do not need to be explicitly declared with a data type before they are used.

JavaScript