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:  
  1. Is there any strategy or strategy?
  2. 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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -