Skip to content

Latest commit

 

History

History
54 lines (32 loc) · 1.23 KB

variables.md

File metadata and controls

54 lines (32 loc) · 1.23 KB

Variables In JavaScript

We can easily describe variables as containers for storing data.

There are several ways through which we can define variables in javascript; either automatically or by using the var, let or const keywords.

Let us have a look at some examples:

Automatic Declaration

In this case, the variables will get declared as variables automatically:

  //Creating a variable named x and storing the value 20 in it
  x=20;

  //creating a variable named y and storing the value 30 in it
  y=30;

  //creating the variable z and storing the sum of variable x and variable y in it
  z=x+y;

Declaration using the var keyword

In this case we are using the var keyword

  //Creating a variable named myAge using the var keyword and storing the value 27 in it

  var myAge=27;

Declaration using the let keyword

  //Creating a variable named herAge using the let keyword and storing the value 25 in it

  let herAge=25;

Declaration using the const keyword

  //Creating a variable named myAge, herAge and OurTotalAge and storing the sum of variable herAge and myAge in the variable OurTotalAge 
  
    const herAge=25;
    const myAge=27;
    const OurTotalAge=herAge+myAge;