What is a variable?

Imagine an address for a physical home. An address references a physical location.

But that address – the letters and numbers that make up an address' representation – is not necessarily tied to a physical location. If the streets and buildings were completely rebuilt with a new layout, the old addresses wouldn't mean much as the streets would likely be laid out differently. There would have to be new addresses made to point to the new physical locations of points of interest. This is similar to how variables work in a computer program.

In Javascript, we can assign a variable to a value like so:

var entree = 'pasta';

This specifies that we have an address entree that is assigned a value of pasta. But it doesn't necessarily mean that the entree can't be reassigned to reference some other value. All I would need to do is:

entree = 'pizza';

If we don't want to allow a variable to change the value that it references, we can use the const keyword instead:

const entree = 'pasta';
entree = 'pizza'; // This statement is illegal now.

The let behaves similarly to how var would behave before the ES6 standard in that it allows for reassignment of the variable to different values.

The nuanced difference is that a let variable is block scoped. The simplest way to explain this is with an example:

if (true) {
  var entree = 'pasta';  
console.log(entree); // pasta

if (true) {
  let dessert = 'tiramisu';
console.log(dessert); // Error: dessert is not defined.

In practice, I always use const and let. I have not found any practical reason for using the less restrictive var.