javascript - Using && as a replacement for IF statement -
I found the following snippet when digging through some code:
"string" ! = myVar type & amp; Amp; (MyVar = ""); I understand what happens here. If myVar is not a string, then the first condition is true, the second condition is evaluated, so that my veril can be set to "". Therefore it is essentially the replacement for the following:
if ("string"! = MyVar type) myVar = ""; The only obvious difference is that there is a return statement even before two strategies, although I found that the code is not using the returned value. So I am thinking: - Is there any strategy or strategy?
- If the only supporters for the first strategy have the ability to return a value, then snippets are considered bad programming because it is more difficult to read?
Just to indicate, less obvious use of this idiom is more obvious .
"string"! = Type myvar & amp; Amp; (myVar = ""); I have read it and actually had to change it in my head / if. Steve McConnell argued that there should be a line of code per work, with which I agree and whose condemnation it is. Also keep in mind that the embedded side effects are dangerous at first place, that's great.
parameter = parameter || {}; Var speed = parameter.p speed || 60; IMO is a very clear use, partly because it is a well established idiom or
if (X & x.employer.company === 'google') Clear use of idioms (for example, if you do undefined.company You will get an exception).
Comments
Post a Comment