Skip to content

Variables

A variable is a named container for data. The name of the variable is up to you (take a look at naming guidelines in the Style Guide), but ideally, it should be easy to write and remember while also providing context for the data being stored.

To declare a variable, start with the keyword const (for values that will not change) or let (for values that may change) and assign the value using =.

const profName = "Eric"; // will never change
let profCity = "Oxford"; // may change in the future
const x = 2021; // terrible variable name, what is it for?
const year = 2021; // not a great variable name, too generic
const yearHired = 2021; // better variable name

When using the console with embedded CodePen examples, you should open the Pen in its own window by clicking Edit On CodePen and then clicking the Console button in the CodePen editor.

See the Pen Variables (IMS322 Docs) by Eric Sheffield (@ersheff) on CodePen.