Challenge - 5 Problems
String Concatenation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of concatenated strings with numbers
What is the output of this JavaScript code?
console.log('5' + 3 + 2);Javascript
console.log('5' + 3 + 2);
Attempts:
2 left
💡 Hint
Remember that + with a string converts numbers to strings and concatenates.
✗ Incorrect
The + operator with a string converts numbers to strings and concatenates from left to right. '5' + 3 is '53', then '53' + 2 is '532'.
❓ Predict Output
intermediate2:00remaining
Concatenation with template literals
What will this code output?
const a = 4;
const b = 5;
console.log(`${a} + ${b} = ${a + b}`);
Javascript
const a = 4; const b = 5; console.log(`${a} + ${b} = ${a + b}`);
Attempts:
2 left
💡 Hint
Template literals evaluate expressions inside ${}.
✗ Incorrect
The template literal replaces ${a} with 4, ${b} with 5, and ${a + b} with 9, so the output is '4 + 5 = 9'.
❓ Predict Output
advanced2:00remaining
Output of mixed concatenation and addition
What is the output of this code?
console.log('3' + 2 * 2);Javascript
console.log('3' + 2 * 2);
Attempts:
2 left
💡 Hint
Remember operator precedence: * before +.
✗ Incorrect
2 * 2 is 4, then '3' + 4 converts 4 to string and concatenates, resulting in '34'.
❓ Predict Output
advanced2:00remaining
Concatenation with null and undefined
What will this code print?
console.log('Value: ' + null + undefined);Javascript
console.log('Value: ' + null + undefined);
Attempts:
2 left
💡 Hint
null and undefined convert to strings when concatenated.
✗ Incorrect
null converts to 'null', undefined converts to 'undefined', so concatenation results in 'Value: nullundefined'.
🧠 Conceptual
expert3:00remaining
Why does this concatenation produce unexpected output?
Consider this code:
Why does it output '3345' instead of '12345' or a number?
console.log(1 + 2 + '3' + 4 + 5);
Why does it output '3345' instead of '12345' or a number?
Attempts:
2 left
💡 Hint
Think about how + works left to right and when it switches from addition to concatenation.
✗ Incorrect
The + operator is left to right: 1+2=3 (number), then 3 + '3' converts 3 to string and concatenates to '33', then '33' + 4 = '334', then '334' + 5 = '3345'.