code does not what you think! Or am I the only one? #190
-
Ran into this while coding... What do you think the below code will do?
It'll either print out 1 # # 2 or true # # 1. The # # are other number that is not important. What is, is the print of "true" or "1" through the num variable which in turn give me either 1 or 2 through the el2 variable. I think it got something to do with coercer in the turner operand.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You are not writting equivalent code, because in the first you are using the
|
Beta Was this translation helpful? Give feedback.
You are not writting equivalent code, because in the first you are using the
=!
operator and store it innum
variable. Then you use the ternary operator, and in thefalse
condition of the operator you are using another ternary operator, but, if you are reaching thefalse
side of the first operator you are always running++n
wich is leads something likefalse + 1
=>0 + 1
=>1
.This is the actual rewrite of the first function: