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 ...
Get Coding All-in-One For Dummies, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.