what it will print console.log(1+ + “2”)

前端 未结 3 1417
名媛妹妹
名媛妹妹 2021-01-16 22:53

Why does this JavaScript statement:

console.log(1 +  + \"2\");

print

3

as the output? I am not sure why

3条回答
  •  既然无缘
    2021-01-16 23:18

    console.log(1 + "2") prints 12 as + acts as an concatenation operator.

    But if you try to print console.log( + "2" ) you will get output as 2 coz it is casted as an integer.

    Therefore console.log( 1 + +"2" ) will give you result as 3

提交回复
热议问题