Loading ...
Sorry, an error occurred while loading the content.

286Re: Splitting a conditional operator (?:) across multiple lines

Expand Messages
  • Douglas Crockford
    Oct 23, 2008
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "enaeseth" <enaeseth@...> wrote:
      > I'm trying to edit an existing codebase to make it pass JSLint
      > verification so that it can be packed or minified safely. Mostly, my
      > code requires small, obvious changes, but JSLint balks at my common
      > practice of splitting long statements that use the conditional (ternary)
      > operator across three lines, like so:
      > this.foo = (typeof(foo) != "undefined") ? foo : true;
      > What is a safe and acceptable way to write these statements? Some of
      > them are short enough to be written on one line, but most are not.

      Check the documentation page. JSLint recommends breaking lines after
      operators to avoid semicolon insertion mishaps.

      this.foo = typeof(foo) !== "undefined" ?
      foo :
    • Show all 4 messages in this topic