SKU // 12

JavaScript Operators

Operators are the symbols that make things happen: they do the math, store the values, compare things, and combine answers. You have already used a few. This lesson is the map of the whole territory: what each group of operators is for, with a quick taste of each. The next few lessons then go deep on the groups one at a time.

let x = 5;            // assign 5 to x
let y = 2;            // assign 2 to y
let z = x + y;        // add them, assign the result to z
let big = z > 5;      // compare: is z greater than 5?
console.log(z, big);
7 true

// Operands and Operators

The values an operator works on are called operands. The operator is the symbol that says what to do with them:

Operand Operator Operand
100+50

Most operators take two operands, one on each side. These are called binary operators. A few take just one and are called unary. And exactly one operator takes three, the conditional ? :, which is why it is often just called the ternary (from the Latin for "three"):

// Binary: two operands
5 + 3
10 * 2

// Unary: one operand
-x               // negation: flips the sign
!true            // logical NOT: gives false
typeof 42        // gives "number"

// Ternary: three operands
age >= 18 ? "adult" : "minor"

// Types of Operators

Group Symbols What they do Full lesson
Arithmetic+ - * / % ** ++ --Math on numbersJS Arithmetic
Assignment= += -= *= /= %= **=Store values in variablesJS Assignment
String+ +=Join text togetherthis lesson
Comparison== === != !== > < >= <=Compare values, give true/falseJS Comparisons
Logical&& || !Combine true/false answersJS Logical
Conditional? :Pick one of two valuesJS Ternary
TypetypeofReport a value's typeJS typeof

// Arithmetic Operators

Arithmetic operators do math on numbers. Operands can be literals, variables, or whole expressions:

let a = 3;
let x = (100 + 50) * a;
console.log(x);
450
+Addition/Division
-Subtraction%Remainder (modulus)
*Multiplication++Increment (add 1)
**Exponentiation (power)--Decrement (subtract 1)

// Assignment Operators

= stores a value. The compound assignment operators do a bit of math and store the result in one step, so you do not have to write the variable name twice:

let x = 10;
x += 5;          // same as x = x + 5
console.log(x);
15
Operator Example Same as
=x = yx = y
+=x += yx = x + y
-=x -= yx = x - y
*=x *= yx = x * y
/=x /= yx = x / y
%=x %= yx = x % y
**=x **= yx = x ** y

// String Operators

When used on strings, + is called the concatenation operator: it joins them end to end.

let text1 = "John";
let text2 = "Doe";
let text3 = text1 + " " + text2;    // note the " " for the space
console.log(text3);
John Doe

+= works on strings too, adding text onto the end of what is already there:

let text = "What a very ";
text += "nice day";
console.log(text);
What a very nice day

Adding strings and numbers

Adding two numbers gives a number. But if either operand is a string, + joins instead of adding, and the result is a string:

let x = 5 + 5;
let y = "5" + 5;
let z = "Hello" + 5;
console.log(x);
console.log(y);
console.log(z);
10 55 Hello5
Watch out: only + does this
+ is the only arithmetic operator that joins strings. The others (- * / %) have no string meaning, so they convert the string to a number and do the math. "10" + 5 is "105", but "10" - 5 is 5. Same values, completely different kinds of answer.

// Comparison Operators

Comparison operators compare two values and always give back true or false. Given let x = 5;:

Operator Meaning Example Result
==equal tox == 5true
===equal value and equal typex === "5"false
!=not equalx != 8true
!==not equal value or not equal typex !== "5"true
>greater thanx > 8false
<less thanx < 8true
>=greater than or equal tox >= 8false
<=less than or equal tox <= 8true

They work on strings too, comparing alphabetically: "A" < "B" is true. The JS Comparisons lesson covers the surprises that come with that.

// Logical Operators

Logical operators combine true/false answers into one:

&&logical AND: true only if both sides are true
||logical OR: true if either side is true
!logical NOT: flips true to false and false to true
let age = 16;
console.log(age >= 13 && age <= 19);   // a teenager?
true

// Operator Precedence

When an expression has several operators, JavaScript follows an order, just like order of operations in math class. Multiplication and division happen before addition and subtraction; parentheses override everything:

console.log(2 + 3 * 4);      // * first: 2 + 12
console.log((2 + 3) * 4);    // parentheses first: 5 * 4
14 20
Tip
When in doubt, add parentheses. They make your intent obvious, both to JavaScript and to the next person reading your code. The full precedence rules are in JS Arithmetic.

// Quick Check

Which of these is a unary operator?

  1. *
  2. typeof
  3. ===
  4. +=
Show answer
B. typeof takes a single operand (typeof 42). The other three all need a value on each side.

What do these log?

console.log("8" + 2);
console.log("8" - 2);
Show answer
82 and 6. With a string involved, + joins. - has no string meaning, so it converts "8" to the number 8 and subtracts.

Every comparison operator gives back which type of value?

  1. A number
  2. A string
  3. A boolean
  4. Whatever type the operands are
Show answer
C. A comparison always answers with true or false, no matter what is being compared.

// Try It

  1. Click Open Playground. Predict both lines, then click Run. Which operator went first on line 1?
  2. Log "10" + 5, "10" - 5, and "10" * 5. Then log the typeof of each result
  3. Build a full name: let name = "Ada"; then use += to add a space and a last name. Log it
  4. Declare let x = 5; and log every comparison operator from the table against 8. Predict each answer first
// Video Walkthroughs
Last updated: Oct 9, 2026, 9:46 PM ET