← Trail· Lesson 3 of 10
See this lesson in TypeScript →
Operators and expressions
Calculate, compare values and combine conditions with && and ||.

An expression combines values and operators to produce a result. 3 * 10 gives 30; 30 >= 18 gives true.
| Operator | Purpose | Example |
|---|---|---|
+, - |
Add and subtract | 10 - 3 → 7 |
*, / |
Multiply and divide | 3 * 10 → 30 |
% |
Division remainder | 7 % 2 → 1 |
===, !== |
Strict equality and inequality | 20 === '20' → false |
>, <, >=, <= |
Compare values | 18 >= 18 → true |
Prefer === to == as you start: strict comparison does not automatically convert text to numbers. With text, + may concatenate: '2' + 3 gives '23'.
Combine conditions
For booleans, && means AND: both must be true. || means OR: at least one must be true. A fictional party rule is: at least 18 years old AND (has an invitation OR is accompanied).
Write idade >= 18 && (temConvite || acompanhado). Parentheses make the rule clear. > excludes 18; >= includes it.
Try it
Change quantity, price and balance. Predict the console output before reading it.
Execute o código para ver a saída aqui.Exercise: apply the party rule
Complete podeEntrar(idade, temConvite, acompanhado) (may enter, age, has invitation, is accompanied). Return a boolean: age 18 or more AND (invitation OR companion).
The starter excludes exactly 18 and ignores the companion. Fix the expression after return, keeping the name. Use >=, &&, || and parentheses, then click Verificar. Feedback is in Portuguese.
Execute o código para ver a saída aqui.Edite o JavaScript e clique em Verificar.
Next step
Boolean expressions will power if/else decisions. Next, use those expressions in decisions with if/else and switch.