O'Reilly logo

Learning JavaScript, 3rd Edition by Ethan Brown

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

let currentTempC = 22;  // degrees Celsius
Note

The let keyword is new in ES6; prior ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required