Comparison and precedence
"10" < "9" compares text letter by letter; "10" < 9 converts the string to a number first. - runs left to right, ** right to left.
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?
Console
(nothing was printed)Expected console output
true true false
true true false
true false
false false false
14
20
3
512
true