img

Variables are Storing Data Container

JS Variable can be declared in 4 ways :

  1. Automatically
  2. Using var
  3. Using let
  4. Using const

Note :

It is considered good programing practice to write always declare variables before use.

The var keyword was used in all JavaScipt code from 1995 – 2015.

The let and const keywords were added to JavaScript in 2015.

The var keyword should only be used in code written for older browsers.

When to use var, let and const?

  1. Always declare variables.
  2. Always use const if the value should not be changed
  3. Always use const if the typw should not be changed (array and objects).
  4. Only use let if you can’t use const
  5. Only use var if you Must support old brwosers.

 

Related Posts