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

Learning Plan 3 Unary Operators

# Unary Operators

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

> These are really handy and we'll use them all the time.

### The Unary Operators

Operator | Function
`++` | Increments a Number
`--` | Decrements a Number
`typeof` | Returns a string representing the data type

### Using the Unary Operators

> These are a few handy shorcuts.

> Unary means that there is only one variable or value involved with the operator. Usually we have to have something on either side of the operator, like the plus sign. But, these just have one.

- Here's the first way we've seen to add one to a number

- But this is too much typing!

        myCount = myCount + 1;

- Fortunately, we have a shortcut. This does the same thing.

        myCount++; // Increment, or add one, to myCount

- We use it like this.

- I bet you can guess what this one does!

        myCount--; // ???

- That's right, it subtracts one from myCount

- We're only going to look at one other unary operator: `typeof()`. It looks like a call to a function with parentheses. It tells us what type of data we have. It actually returns the strings "`number`", "`string` ", and "`boolean` ".

        typeof(5) <-- this will be "number"

- Using `typeof`

### A Lab is Next:

> Here's some unary practice: 3.3 Lab 3