Like VB has operators AndAlso and OrElse, that perform short-circuiting logical conjunction, where can equivalent operators be found in JS / AS?
+2
A:
The normal && and || operators do short circuit evaluation.
Matthew Crumley
2009-01-28 06:55:38
+1
A:
From what I gather, JS and AS use short-circuiting by default.
Defaults might be a good example:
var value = input || false; // defaults: non-zero `input` or `false`
Ternary is another -- only the block needed is executed:
return typeof(value) == 'string' ? value.substr(0, 2) : '';
Jonathan Lonowski
2009-01-28 06:58:06
The ternary is an evil eveeeel statement that should be avoided at all costs imo. Just too freaking hard to read! I've lost count of the number of bugs I've found in code because someone thought they'd be cute and use the ternary...
GeoffreyF67
2009-01-28 07:42:52