While reading the coffee script document, I was confused by the documentation states
? = ) can also be used for secure conditional assignments compared to= = , in cases where you may have to handle numbers or stars.
? What is the difference between operator and?
and= completely different (but overlapping) conditions
|| Operator works the same way as it does in JavaScript, such as0 and'' are false as far as|| Regarding ;|| Checks for validity in javascript sense.What
? The operator is converted to javascript in== zeroA? B is onlyb whena isnull orundefined ; Coffee code means? Definition of check.Consider these:
for [wrong, 0, '', blank, undefined, 6] do (V) - & gt; A = VA || = 'Pancakes' console.log ("# {v}} = 'pancakes':", a for v [false, 0, '', null, undefined, 6] do (v) - & gt; A = VA? = 'Pancakes' console.log ("# {v}? = 'Pancakes':", a)The first loop will give you five pancakes and one
6 , The second loop gives you afalse ,0 ,'' , two pancakes and a6 .DEMO:
So if you only want JavaScript style behavior (i.e.
0 ,false , and'' is to be ignored), then you probably want= = . If you want to leave onlynull andundefined , you want? = .
No comments:
Post a Comment