Solice UI
Back to the curriculum

Chapter 4 · JavaScript & the DOM

Variables and data types

Programs work with values: names, counts, yes-or-no choices, and collections of related information. Variables give those values useful names so later code can read or update them.

Beginner · Lesson 1 of 6 in this chapter

The type describes the kind of value

Strings represent text, numbers support arithmetic, booleans represent true or false, and null can intentionally mean no value. Arrays and objects organize several values into useful structures.

Names should explain the role

A variable such as itemCount communicates more than x. Use const when the binding will not be reassigned and let when the program intentionally changes which value the name refers to.

Representing a cart summary

  1. A number stores the item count.
  2. A string stores the visible currency label.
  3. A boolean records whether checkout is currently available.
  • Choose a data type that matches the value's meaning.
  • Give variables names that explain their role.
  • Use const by default and let for intentional reassignment.