0

What is "2" + "2" - "2'" on JavaScript? Can I get explanation to it

I've been having various questions on solving calculations on JavaScript. I'd need some help here

17th May 2021, 3:06 PM
Onyeji Chiagozie Victor
2 odpowiedzi
+ 3
+ is both additional and concatenation in javascript so it concatenation if any one is not number. But - meaning only subtraction Therefore "2"+"2" = 22 22 - 2 = 20
17th May 2021, 3:13 PM
Ayush Kumar
Ayush Kumar - avatar
+ 1
丹ⓨㄩک廾 almost ^^ exactly "2" + "2" = "22" "22" - "2" = Number("22") - Number("2") = 22 - 2 = 20 I guess you know that, but I think Onyeji Chiagozie Victor isn't necessary aware of implicit casting under the hood ;)
17th May 2021, 8:58 PM
visph
visph - avatar