0
Why code does not work right?
As I could understand, the right writing of "? :" is in unworkable code, while if it is the second one — it works correct. What is the problem? https://code.sololearn.com/WtqS2er32B9E/?ref=app https://code.sololearn.com/WVI510i8TeXC/?ref=app
1 Answer
+ 9
(a > b) ? 'a>b' ? (a = b) : 'a=b' : 'a<b';
in this code 'a>b' is a string which is evaluated to true (condition is evaluated first )
while in
(a > b) ? 'a>b' : (a = b) ? 'a=b' : 'a<b';
the (a=b) is evaluated which sets a to 15 which is truthy .. so it finally becomes 'a=b'