Chapter 9

Putting It Together with Operators

An operator is a symbol that performs a task (an operation) using operands. In this chapter, you learn about the different types of operators you can work with in JavaScript.

JavaScript has an operator for every need and a couple operators that you’ll probably never need. Instead of simply listing all the operators, let’s write a program that lets you choose operators and enter in operands and then see the results.

The program will be a Super-Calculator — it can work with words and letters as well as numbers.

image

Introducing the Super-Calculator

You’ve never seen a calculator like this before. Friends, this calculator can do your everyday arithmetic — it can add, subtract, multiply, and even divide. But wait, there’s more! It can also take any two numbers — that’s right, ANY TWO NUMBERS — and tell you how much is left over when you divide one by the other. We call that amazing feature a modulo operation. Get your modulo operation done right here! Free!

But that’s not all! This here Super-Calculator can take words and stick them together! Let’s say you have the word Java and you have the word Script and you wanted to somehow glue them together. Impossible, you say? Hard to believe? Not with the Super-Calculator!

The Super-Calculator gives you the power to glue words together — heck, you can even glue entire sentences — using the concatenation ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.