JavaScript - Variables

Javascript variables are containers that store values, which can be numbers, strings, objects, arrays, etc. They are declared using the "var", "let", or "const" keyword, followed by a name and an assignment operator (=) to assign a value.

Example :

var x = 10;

let y = "Hello";

const z = true;

 

  • The "var" keyword is used to declare a variable with function scope, meaning it is accessible within the function it was declared in and its nested functions.
  • The "let" keyword is used to declare a variable with block scope, meaning it is only accessible within the block it was declared in and its nested blocks.
  • The "const" keyword is used to declare a constant variable, meaning its value cannot be changed once assigned.