Chapter 2. Variables: storing data in your program

 

This chapter covers

  • Storing and using information with variables
  • Declaring variables
  • Assigning values to variables
  • Displaying variable values on the console

Get Programming with JavaScript has been written as a gentle introduction to programming. This chapter, then, is a gentle introduction to a gentle introduction. As far as adventures go, you hardly leave the house. You can think of it as the packing stage for your journey, vitally important—you don’t want to get to the airport without your passport or to the Oscars without your selfie stick—but not the main event.

Almost without exception, programs store, manipulate, and display data. Whether you’re writing a system for blogging, analyzing engine performance, predicting the weather, or sending a probe to land on a comet in 10 years’ time, you need to consider the data you’ll use and what kinds of values that data might take. To work with data in your programs, you use variables.

2.1. What is a variable?

2.2. Declaring variables and assigning values

2.3. Choosing good variable names

2.4. The Crypt—player variables

2.5. Summary

sitemap