Utilizor
Contact Us

JS Variables

JavaScript variables are containers for storing data values.

Declaring JavaScript Variables

In JavaScript, you can declare variables using var, let, or const.

  • var: The historical way to declare variables. It has function scope.
  • let: Introduced in ES6, let allows you to declare variables with block scope.
  • const: Also introduced in ES6, const declares block-scoped variables whose values cannot be reassigned.

It's common practice to declare all variables at the beginning of a script or function.

Example

let x = 5;
let y = 6;
let z = x + y;
console.log(z); // Outputs 11