Code Lab

String plus number

EasyBasics3 min

What does this program print? Write the output: one line for each console log call, in the same order.

const s = 21 + 'abc' + 49 + 14;
console.log(s);

const t = 21 + 49 + 'abc' + 14;
console.log(t);
  • The program mixes numbers and strings with +. Think about when + adds numbers and when it joins text (concatenation), and when JavaScript turns a number into a string by itself (type coercion).
  • Type each line exactly as the console shows it: a string is printed without quotes.

Program

const s = 21 + 'abc' + 49 + 14;
console.log(s);

const t = 21 + 49 + 'abc' + 14;
console.log(t);

Asked at Mastercard · Source

Predict the output
Loading the editor...
Run your code to see the test results here.