+ 1

In JS console.log(+'solo'+'learn'), why the output =NaNlearn

20th Jun 2020, 5:10 PM
Kazi Alauddin
Kazi Alauddin - avatar
4 Respuestas
+ 4
Adding + operator before an operand converts it to a positive integer. If the operand is not a number it returns NaN So +'solo' gives NaN and +'solo'+'learn' gives NaN+'learn JavaScript automatically converts NaN to a string before concatenation. Hence the result. I know what you are thinking and yes I agree implicit type conversion is confusing.
20th Jun 2020, 9:25 PM
Ore
Ore - avatar
+ 3
Kazi Alauddin Actually don't no details. I just know operand + & - in font of a string converts it to number. IF +"2" = 2 -"2" = -2 +"hlw" = NaN -"hlw" = NaN
20th Jun 2020, 5:37 PM
Sharmin Rumpa
Sharmin Rumpa - avatar
0
Kazi Alauddin string er age + thakle Nan2nd string
20th Jun 2020, 5:25 PM
Sharmin Rumpa
Sharmin Rumpa - avatar
0
Sharmin Rumpa I ask why.? Not the answer
20th Jun 2020, 5:27 PM
Kazi Alauddin
Kazi Alauddin - avatar