Why JavaScript Data Types are Dynamic?


JavaScript also has dynamic types. That would mean the same variable used for holding different data types in JavaScript.

Example

<html>
   <head>
      <script>
         var val;
         val = "Amit";
         document.write("String: "+val);

         val = 20;
         document.write("<br>Number: "+val);

         val = 40.90;
         document.write("<br>Number with decimals: "+val);
      </script>
   </head>
   <body>
   </body>
</html>

Updated on: 16-Jan-2020

119 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements