JavaScript Variables

Variables are containers for storing data in JavaScript.

JavaScript Variables can be declared in 4 ways:

Automatically

Using var

Using let

Using const

  1. Automatically

    They are automatically declared when first used:

    x = 5;

    y = 10;

    z = x + y;

  2. Using var

    The var keyword was used in all JavaScript code with the old browser.

    Example:

    var carName

  3. Using let

    It is used only if you can’t use const

    Example:

    let carName = “volvo”;

  4. Using const

    It is used if the data type is not changing i.e (Arrays and Objects)