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

Re: Ternary Indentation Question

Expand Messages
  • Marc Spoor
    ... I was under the impression that a line that starts with the return statement should end with a semicolon, in order to not give the interpreter a chance to
    Message 1 of 8 , Jan 18, 2012
    • 0 Attachment
      > I would write it this way:
      >
      > function test(x) {
      > ~~~~'use strict';
      > ~~~~return x === 1
      > ~~~~~~~~? 'one'
      > ~~~~~~~~: x === 2
      > ~~~~~~~~? 'two'
      > ~~~~~~~~: x === 3
      > ~~~~~~~~? 'three'
      > ~~~~~~~~: x === 4
      > ~~~~~~~~? 'four'
      > ~~~~~~~~: 'zero';
      > }
      >
      > The placement of ? and : makes it easier to read them as then and else if.

      I was under the impression that a line that starts with the return
      statement should end with a semicolon, in order to not give the
      interpreter a chance to mess it up.

      I can't test it in IE6 right now, but isn't it conceivable that a dull
      browser would turn the above function into "return x===1;"?

      Or does the "'use strict';" prevent that sort of misguided benevolence?
    Your message has been successfully submitted and would be delivered to recipients shortly.