Skip to main content

Operators

Arithmetic Operators

OperatorDescriptionExampleResult
+Addition2 + 35
-Subtraction7 - 43
*Multiplication3 * 515
/Division10 / 33.33
%Modulo10 % 31
^Exponentiation2 ^ 101024
-Unary negation-5-5
+Unary plus+55

The + operator also concatenates strings: "Hello" + " World" produces "Hello World".

Comparison Operators

OperatorDescriptionExampleResult
==Strict equal3 == 3true
!=Strict not equal3 != 4true
>Greater than5 > 3true
<Less than3 < 5true
>=Greater than or equal5 >= 5true
<=Less than or equal3 <= 5true

Comparison operators return boolean values. Equality uses strict comparison (=== semantics) -- no type coercion is performed.

Logical Operators

OperatorDescriptionExampleResult
&&Logical ANDtrue && falsefalse
||Logical ORtrue || falsetrue
!Logical NOT!truefalse

&& and || use short-circuit evaluation and return the deciding operand value (not coerced to boolean). For example, name || "anonymous" returns name if truthy, otherwise "anonymous".

Operator Precedence

Operators are evaluated in this order (highest precedence first):

PrecedenceOperatorsDescription
1()Parentheses (grouping)
2^Exponentiation
3+ - ! (unary)Unary operators
4* / %Multiplication, division, modulo
5+ -Addition, subtraction
6< <= > >= == !=Comparison
7&&Logical AND
8`

Use parentheses to override precedence:

(2 + 3) * 4    // 20, not 14