Pro Programmer
Variables

Variables

Variables are used in computer programs to hold data. This is a very simplified statement and it is by many measures simply wrong.

Variables do not hold data. They just point to it. Data is held in the computer’s memory. You can compare variables to the labels you place on your email messages (or notes, or files).

In Gmail, a label is a pointer to an email or a list of emails. Many labels can point to the same email. This is similar to assigning another variable to an existing variable:

let work = [email1, email2, email3];
let important = work;

Both work and important are now labels that point to the exact same list of emails.

Some variables represent constant references; they cannot be changed. This is like the “sent” label in Gmail. While we can change the work label above and make it point to a different list of emails, we cannot change the sent label. You cannot point the sent label to a different list of emails. You can only make it point to more emails.

const sent = [];
// You cannot change the meaning of sent now
// But you can add more values to it:
sent.push(new Email());