1. + with a string
If either operand of + is a string, both are converted to strings and concatenated, so "5" + 1 is "51".
"5" + 1 // "51" — string concatenationTyporithm · hard
Step 1 of 8 · intro card
Tricky Output
The + operator concatenates if EITHER operand is a string, otherwise it adds numbers; -, *, / are always numeric. That is why "5" + 1 is "51" but "5" - 1 is 4, and 1 + "2" + 3 is "123".
The binary + operator is overloaded: if either operand is a string (after ToPrimitive), it converts both to strings and concatenates; otherwise it converts both to numbers and adds. So "5" + 1 is "51".
Every other arithmetic operator (-, *, /, %) has only a numeric mode, so it coerces both sides to numbers: "5" - 1 is 4.
Objects and arrays convert via ToPrimitive: [] becomes "", {} becomes "[object Object]". Combined with left-to-right evaluation, 1 + "2" + 3 becomes "12" then "123".
+ concatenates if either side is a string; else it adds.
-, *, / are always numeric coercion.
[] → "", {} → "[object Object]", +"" → 0.
"5" + 1 // "51" — string concatenation
"5" - 1 // 4 — numeric subtraction
[] + [] // "" — both become empty strings
[] + {} // "[object Object]"
+"" // 0 — empty string to number
1 + "2" + 3 // "123" — left to right, string winsConnect each part of the code to the concept before you type.
If either operand of + is a string, both are converted to strings and concatenated, so "5" + 1 is "51".
"5" + 1 // "51" — string concatenationMinus has no string mode, so both operands convert to numbers: "5" - 1 is 4.
"5" - 1 // 4 — numeric subtraction[] becomes "" and {} becomes "[object Object]", and + concatenates them.
[] + {} // "[object Object]"Unary + converts its operand to a number, and an empty string becomes 0.
+"" // 0 — empty string to number1 + "2" is "12", then "12" + 3 is "123" — once a string appears, the rest concatenates.
1 + "2" + 3 // "123" — left to right, string winsRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.