0

Javascript beginner challenge query

Hey What is is the answer to ((“1”)-1==0) I thought it was a type error but the challenge says true Someone please explain

3rd Oct 2019, 8:53 PM
Misanthrope
Misanthrope - avatar
3 odpowiedzi
+ 2
When retrieving a value from a string value and a integer, the string value is automatically converted to an integer value. For instance, "1" == 1 would return true because when comparing them it's automatically converted to an integer and also "2" - 1 would return 1. However, if you had "1" === 1 it would return false because === is comparing if they are the same value and of the same type. In your question, the parentheses around the string may just be there to make you think harder but could be ignored in this case. So with that said "1" - 1 would be 0. So the Boolean would be true.
3rd Oct 2019, 11:25 PM
Anthony Johnson
Anthony Johnson - avatar
+ 1
Thank you for the explanation!
3rd Oct 2019, 11:27 PM
Misanthrope
Misanthrope - avatar
0
Your welcome. I hope this helps.
3rd Oct 2019, 11:29 PM
Anthony Johnson
Anthony Johnson - avatar