Chapter 3. Literals, Variables, Constants, and Data Types
This chapter is about data, and how we translate data into a format that JavaScript can understand.
You’re probably aware that all data is ultimately represented inside a computer as long sequences of ones and zeros—but for most day-to-day tasks, we want to think about data in a way that’s more natural to us: numbers, text, dates, and so on. We will call these abstractions data types.
Before we dive into the data types available in JavaScript, we will discuss variables, constants, and literals, which are the mechanisms available to us in JavaScript for holding data.
Note
The importance of vocabulary is often overlooked when you’re learning to program. While it may not seem important to understand how a literal differs from a value, or a statement from an expression, not knowing these terms will hamper your ability to learn. Most of these terms are not specific to JavaScript, but are commonly understood in computer science. Having a good grasp of the concepts is important, of course, but paying attention to vocabulary makes it easy for you to transfer your knowledge to other languages, and learn from more sources.
Variables and Constants
A variable is essentially a named value, and as the name implies, the value can change at any time. For example, if we’re working on a climate control system, we might have a variable called currentTempC:
letcurrentTempC=22;// degrees Celsius
Note
The let keyword is new in ES6; prior ...
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