Skip to main content

Command Palette

Search for a command to run...

JS Variables

Published
1 min readView as Markdown
JS Variables

The variable is containers for storing the data values.

Four ways to declare a JS Variable:

* Var

* Let

* Const

* Using nothing

Rules of Variables

- Variable names only start with Characters, underscore & $.

-Variable names can be alphanumeric. ex:var55.

-Variable names never start with Numbers or Symbols.

-Variable not be a reserved keyboard.

Example:

let name = "Smitha";
let number = 44;

History of (Var, Const & Let):

-The var keyword is used in all JavaScript code from 1995 to 2015.

-The let and const keywords were added to Javascript in 2015.

-If you want your code to run in older browsers, you must use var.

Scope :

The scope is Space under the curly base{}.

Ways of JS Variables

var :

Var will be alive throughout the code.

     var name = "Mike";

let:

let alive only inside the scope.

    let number = 88;

Const:

Const cannot update the value because of its strong value.

     const name = "Rubi";

More from this blog