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

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

Expand Messages
  • Douglas Crockford
    ... Check the documentation page. JSLint recommends breaking lines after operators to avoid semicolon insertion mishaps. this.foo = typeof(foo) !== undefined
    Message 1 of 4 , 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 :
      true;
    Your message has been successfully submitted and would be delivered to recipients shortly.