What happens if we re-declare a variable in JavaScript?


On re-declaring a variable in JavaScript, the variable value still remains the same.

Example

Let’s see an example. Here, we are declaring the variable age −

<html>
   <body>
      <script>
         <!--
            var age = 20;
            var age;
            if( age > 18 ){
               document.write("Qualifies for driving");
            }
           //-->
      </script>
   </body>
</html>

Updated on: 13-Jun-2020

112 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements