What is the use of declaring variables in JavaScript?


Before you use a variable in a JavaScript program, you must declare it. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.

Variables are declared with the var keyword as follows.

<script>
   <!--
      var rank;
      var points;
   //-->
</script>

You can also declare multiple variables with the same var keyword as follows −

<script>
   <!--
      var rank, points;
   //-->
</script>

This is also you can assign values −

var rank = 2;
var points = 100;


Ali
Ali

Updated on: 13-Jun-2020

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements