DEV Community

Lakshya Tyagi
Lakshya Tyagi

Posted on

What will the code below output to the console and why?

Write your answer in comment

  1. console.log(1 + +"3" + "3");
  2. console.log(1 +"3" + "3");
  3. console.log(1 + -"1" + "3");
  4. console.log(+"1" + "1" + "3");
  5. console.log("X" - "Y" + "3");
  6. console.log("X" - "Y" + 3);

Discussion (7)

Collapse
sharpninja profile image
The Sharp Ninja

What language? Some treat 1 + "3" as numeric arithmetic, others treat ir as string concatenation?

Collapse
lakshyatyagi24 profile image
Lakshya Tyagi Author

javaScript

Collapse
metalmikester profile image
Michel Renaud

There's a Python tag in the question (at first I thought it was JavaScript).

Collapse
lakshyatyagi24 profile image
Lakshya Tyagi Author

yeh sorry by mistake i put wrong tag

Collapse
sharpninja profile image
The Sharp Ninja

Yeah, see that now. Might have been good to clarify that in the question. I don't grok python so I'll pass.

Thread Thread
metalmikester profile image
Michel Renaud

I've been meaning to learn Python for years but... Ooooh! Netflix! LOL