Chapter 3
Giving and Receiving Data
Programs come in many different sizes and have many different purposes. Here are three things all programs have in common:
- A way to receive information from the user
- A way to give information back to the user
- A way to store and work with information in between giving and receiving
Information, or data, that a program receives from a user is called input. What the program gives back to the user is called output. In the time between when a program receives input and produces output, it needs some way to store and work with the various types of data that has been inputted, so it can produce output.
The question of whether it’s better to give or receive isn’t important! It’s all good. In this chapter, you learn how JavaScript can help you to get, receive, and just plain have data!
Mastering Variables
In the real world, when you want to store something, give something away (as a gift, for example), move something, or organize something, you often put it in a box.
JavaScript doesn’t care about heart-shaped boxes of chocolates or shoeboxes with the latest sneakers. What JavaScript loves is data. To store and move around data, JavaScript uses a special kind of box called a variable. A variable is a box you can assign a name to. This name will represent all the data contained in that box, or variable.
Variables make it possible for the same 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