Smal SEO Tool

JavaScript Variables

Variables are containers for storing data values. In this example, x, y, and z, are variables, declared with the var keyword:

javascript
var x = 5;
var y = 6;
var z = x + y;

When to Use var, let, or const?

  1. Always declare variables
  2. Use const if the value should not be changed
  3. Use const if the type should not be changed (Arrays and Objects)
  4. Only use let if you can't use const
  5. Only use var if you MUST support old browsers.

Test Yourself with an Exercise

Which keyword is used for a variable whose value cannot be changed?