O'Reilly logo

JavaScript Recipes: A Problem-Solution Approach by Keith Cirkel, Russ Ferguson

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

© Russ Ferguson and Keith Cirkel 2017
Russ Ferguson and Keith CirkelJavaScript Recipes10.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

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' + '3'); // the two Strings are concatenated, ...

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