0
0
Javascriptprogramming~20 mins

String concatenation in output in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Concatenation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
A'7'
B'55'
C'10'
D'532'
Attempts:
2 left
💡 Hint
Remember that + with a string converts numbers to strings and concatenates.
Predict Output
intermediate
2: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}`);
Aa + b = 9
B4 + 5 = 45
C4 + 5 = 9
D4 + 5 = a + b
Attempts:
2 left
💡 Hint
Template literals evaluate expressions inside ${}.
Predict Output
advanced
2: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);
A'7'
B'34'
C'32'
D7
Attempts:
2 left
💡 Hint
Remember operator precedence: * before +.
Predict Output
advanced
2:00remaining
Concatenation with null and undefined
What will this code print?
console.log('Value: ' + null + undefined);
Javascript
console.log('Value: ' + null + undefined);
A'Value: nullundefined'
B'Value: nullundefinedundefined'
C'Value: nullundefinednull'
DTypeError
Attempts:
2 left
💡 Hint
null and undefined convert to strings when concatenated.
🧠 Conceptual
expert
3:00remaining
Why does this concatenation produce unexpected output?
Consider this code:
console.log(1 + 2 + '3' + 4 + 5);

Why does it output '3345' instead of '12345' or a number?
ABecause + is left to right, 1+2=3, then '3' + '3' = '33', then '33' + 4 + 5 = '3345'
BBecause JavaScript converts all numbers to strings before adding
CBecause the + operator always performs string concatenation
DBecause the expression is evaluated right to left
Attempts:
2 left
💡 Hint
Think about how + works left to right and when it switches from addition to concatenation.