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

Unclear expression evaluation of ? :

Expand Messages
  • Woomla
    Hi, In the code snippet below, b will always be is TRUE . Clearly the intention was that b should be a is FALSE . No javascript error but the result is
    Message 1 of 2 , Feb 17, 2010
    • 0 Attachment
      Hi,

      In the code snippet below, b will always be 'is TRUE'. Clearly the intention was that b should be 'a is FALSE'. No javascript error but the result is wrong.

      Maybe jslint could issue a warning in this case, something like: 'use parenthesis to clarify'.


      var a, b;
      a = false;
      b = 'a ' + a ? 'is TRUE' : 'is FALSE';
    • William Chapman
      ... [Non-text portions of this message have been removed]
      Message 2 of 2 , Feb 18, 2010
      • 0 Attachment
        On Wed, Feb 17, 2010 at 12:22 AM, Woomla <woomla@...> wrote:

        >
        >
        > Hi,
        >
        > In the code snippet below, b will always be 'is TRUE'. Clearly the
        > intention was that b should be 'a is FALSE'. No javascript error but the
        > result is wrong.
        >
        > Maybe jslint could issue a warning in this case, something like: 'use
        > parenthesis to clarify'.
        >
        > var a, b;
        > a = false;
        > b = 'a ' + a ? 'is TRUE' : 'is FALSE';
        >
        > This works for me: b = 'a' + (a ? 'is TRUE' : 'is FALSE')


        >
        >


        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.