a = "5"; b = 2; c = a+++b;
The explanation is not correct. It is not a problem of precedence. Yes `++` operator has precedence over `+`. But here, it is the Left to Right order that matter. First, `var a` is evaluated, and there is an automatic conversion from string to number : a is 5 on the Left side of the addition. Then `a` is incremented. Second, the left side is evaluated. So, on the left side of the addition: 2. The addition itself is processed : 5 + 2 => 7. You have to make the difference between the evaluation of each side of the addition and the re-assignement of the `var a` which takes place after because it is a suffix increment and not a prefix one.
2018 Aug 26, 3:37:13 PM
let str = "5"; undefined typeof str; "string" str++ 5 typeof str "number"
2017 Dec 15, 5:05:37 PM
Hi I check for me and i made something in console this it will be useful for you to understanding
2017 Dec 15, 5:05:26 PM
@aalaminosz26 thanks! updated explanation, added "read more" section. While applying unary operator it automatically converts to the number. Read more here: https://scotch.io/tutorials/javascript-unary-operators-simple-and-useful
2017 Dec 5, 3:58:48 PM
Also it is not clear when is the string "5" converted into numeral 5?
2017 Nov 25, 8:10:58 AM
I find the explanation confusing. Maybe the fact that it is all in one line.
2017 Nov 25, 8:09:15 AM
@iliana000, we repeat questions intentionally. Soon there will be more questions, and functionality will train you on sub-topics, that you answered wrong before.
2016 Jan 20, 5:49:31 PM
Login in to like
Login in to comment