Chapter 8

Building Your Dream Car with Operands

When you speak or write in a human language, you typically string together nouns and verbs to create action. You might then spice things up with adjectives, adverbs, pronouns, conjunctions, prepositions, and interjections. However, the real work of a sentence is done by the nouns and verbs.

Forming JavaScript sentences is called writing statements. Statements are mostly made up of operands (which are like nouns) and operators (which are like verbs).

In this chapter, you learn about the different types of operands and you see examples of how to work with operands in JavaScript programs.


Knowing Your Operands

An expression in JavaScript is any valid piece of code that resolves to a value.

When we say that an expression “resolves to a value,” what we mean is that when everything the computer needs to do is done, some sort of value is produced. For example,

  • The expression 1 + 1 “resolves to” 2. Another way to say the same thing is that it has the value of 2.
  • The expression x = 7 is a different kind of expression. It assigns its value (7) to the variable called x.

Expressions are made up of operands (such as the number 1 or the variable x) and operators (such as = or +). Operands can be any of the JavaScript data types that we talk about in Chapter 3, as well as objects or arrays.

In this chapter, we show you how to create and ...

Get JavaScript For Kids For Dummies now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.