© Russ Ferguson and Keith Cirkel 2017

Russ Ferguson and Keith Cirkel, JavaScript Recipes, 10.1007/978-1-4302-6107-0_2

2. Working with Expressions

Russ Ferguson and Keith Cirkel2

(1)Ocean, New Jersey, USA

(2)London, UK

Performing an Addition with the + Operator

Note

String concatenation is covered in more detail in Chapter 3.

Problem

You want to add some numbers together.

Solution

JavaScript has a set of recognizable math operators, including the addition (+) operator, which you can use to add numbers (or variables of numbers) together.

The Code

Listing 2-1. Performing an Addition with the + Operator
console.log(2 + 1);var myNum = 14;var anotherNum = 22;console.log(anotherNum + myNum);console.log(myNum + 0.23);console.log(anotherNum + 16 + myNum + 14);console.log('45' ...

Get JavaScript Recipes: A Problem-Solution Approach 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.