Northcentral Technical College Introduction To Programming
10-152-310
Introduction to Programming with JavaScript NTC 10-152-310

Learning Plan 3 Operators That Add and Subtract

# Operators That Add and Subtract

#### File: /Learning Plan 3/addSubtractOperators.html

> These seem simple at first but there are a few surprises.

### The Additive Operators

> In math, additive refers to both addition and subtraction. You can think of subtraction as just adding with negative numbers.

- The plus sign (`+`) is used for math addition and string concatenation.
- The minus sign (`-`) is used for math subtraction.

### Using the Additive Operators

- Adding and Subtracting Directly into Variables.

- Adding and Subtracting with Variables

- Concatenation of strings. The plus sign (`+`) is also used for concatenation, or combining string to form a new longer string. Notice that the `<br />` tags are being concatenated too.

- Concatenation of Strings and Numbers. When the plus sign has one string to its left OR right and a number on the other side, the number will be converted to a string and concatenated to the string.

- Concatenation when you don't expect it!. When you have a string that contains just numbers and you try to add it to a true number JavaScript will concatenate it and not do addition.

- Converting from a string to a number. When you have string that contains a valid number, you can convert it to a number. We use the `Number()` function for this.

### You Guessed Right!

- Here's the practice lab for this activity: 3.2 Lab 1
  - Here is the assignment that goes with this lab. 3.2 assignment 1