Chapter 3
Working with Variables
IN THIS CHAPTER
Creating and using variables
Understanding variable scope
Knowing JavaScript’s data types
Naming variables
Using built-in functions to work with variables
“Beauty is variable, ugliness is constant.”
— DOUGLAS HORTON (1891 – 1968)
In this chapter, you discover how to create variables, fill them with values, use functions to find out what type of data is in your variables, convert between different data types, and manipulate the data in your variables.
Understanding Variables
Variables are representative names in a program. Just as x may stand for some as-yet-unknown value in algebra, or x may mark the spot where the treasure is buried on a pirate’s map, variables are used in programming to represent something else.
You can think about variables as containers that contain data. You can give these containers names, and later you can recall and change the data in a variable by using its name.
Without variables, every computer program ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access