When + joins instead of adding
Only + joins. -, *, / and unary + always convert to numbers. Left-to-right order explains 33 vs 123.
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.
Write a line that prints whether the number n = 17 is even or odd using %.
A shop sells pens at 12 rupees. Read the quantity "4" (a string, as from an input), and print Total: 48.
Without running it, predict what console.log(3 + 4 * 2 ** 2 - 1) prints, then check.
Explain it without notes
Why does "5" + 2 give "52" while "5" - 2 gives 3?
What is the difference between x++ and ++x?
What is operator precedence, and how do you control it?
Why is "10" < "9" true but "10" < 9 false?
Preview
Console
Nothing logged yet.Expected console output
string
33
123
3
10
42 0 NaN
2