1

Like VB has operators AndAlso and OrElse, that perform short-circuiting logical conjunction, where can equivalent operators be found in JS / AS?

2 Answers 2

2

The normal && and || operators do short circuit evaluation.

Sign up to request clarification or add additional context in comments.

Comments

1

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) : '';

2 Comments

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...
i disagree. ternary operators are straightforward, simple, and concise.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.