How am I getting 339 as output of the following code ?
console.log(3 + '4' + 5 - 6)
can anyone please explain me?
3 + "4" yields "34" due to the implicit string conversion. Implicit string conversion seems to have higher priority than implicit number conversion.
"34" + 5 yields "345"
"345" - 6 yields 339 due to the implicit number conversion
1 + 2 + "3" is "33" because the first operation is 1 + 2 and then it's 3 + "3". There is no priority of conversions.<number> + <string> will always convert to a string.