Computer >> Computer tutorials >  >> Programming >> Javascript

Which data is stored in var and how its content is changed in JavaScript?


JavaScript variables are not typed but their values do have a type. The same variable can be assigned new values.

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         var a;
         document.write(typeof a+"\r\n");
         a = true;
         document.write(typeof a+"\r\n");
         a = 5;
         document.write(typeof a+"\r\n");
         a = "web";
         document.write(typeof a+"\r\n");
      </script>
   </body>
</html>