Back to questions
JuniorTheoryCommon
What does the program print?
console.log("5" + 3, "5" - 3, "5" * "2");53 2 10
- Expecting
8for"5" + 3: when one side of+is a string,+joins strings instead of adding, so the number3becomes"3"and the result is"53". - Expecting
NaNfrom-or*with strings: these operators work only with numbers, so they turn"5"and"2"into5and2first.
- What does
"5" - "x"print, and why? - How would you make
"5" + 3print8?