Skip to content

Ternary operators, again #89

Description

@lxg

I agree that multi-line ternary operators make sense. However, the following is (as far as I know) bad, due to ASI:

var foo = (a === b)
    ? 1
    : 2;

JShint will throw an error on this code, saying “Bad line breaking before '?'”.

If you insist on using multi-line ternary operators, you might prefer the following style:

var foo = (a === b) ?
    1 :
    2;

I agree that it is less readable, because the question mark and the colon are more obvious at the beginning of the line. But I wouldn’t want to mess with ASI and depend on implicit fixes of the JS engine, either.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions