Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 2.1 — Operators
JavaScript · Example 3 of 4

Assignment, increment and decrement

Operators are the symbols that combine values into new values: + - * / % ** for maths, = and += to store results, ++ and -- to count, < > <= >= to compare, and + again to join strings, all evaluated in a fixed order called precedence.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a line that prints whether the number n = 17 is even or odd using %.

02

A shop sells pens at 12 rupees. Read the quantity "4" (a string, as from an input), and print Total: 48.

03

Without running it, predict what console.log(3 + 4 * 2 ** 2 - 1) prints, then check.

Explain it without notes

01

Why does "5" + 2 give "52" while "5" - 2 gives 3?

02

What is the difference between x++ and ++x?

03

What is operator precedence, and how do you control it?

04

Why is "10" < "9" true but "10" < 9 false?

Assignment, increment and decrement

Console

(nothing was printed)

Expected console output

score: 8
postfix: 6 5
prefix: 6 6
chained: 0 0