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

what is the purpose of '(' in eval

Expand Messages
  • geoffreyk00
    I have been looking at JSON, and have seen in a few places where the eval statement is written x = eval( ( + var + ) ); what is the purpose of the ( and
    Message 1 of 3 , Jun 24, 2006
    • 0 Attachment
      I have been looking at JSON, and have seen in a few places where the
      eval statement is written
      x = eval('(' + var + ')');

      what is the purpose of the '(' and ')'

      The tests that I have tried are successful when I don't use them

      Thanks
    • Douglas Crockford
      ... In Javascript there is a potential syntactic ambiguity in which {...} can be interpreted as either a block statement or an object literal. The parens
      Message 2 of 3 , Jun 25, 2006
      • 0 Attachment
        > I have been looking at JSON, and have seen in a few places where the
        > eval statement is written
        > x = eval('(' + var + ')');
        >
        > what is the purpose of the '(' and ')'

        In Javascript there is a potential syntactic ambiguity in which {...}
        can be interpreted as either a block statement or an object literal.
        The parens disambiguate.
      • geoffreyk00
        ... the ... OK. Thanks Could you give a simple example where this would fail? Would help to understand better
        Message 3 of 3 , Jun 25, 2006
        • 0 Attachment
          --- In json@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
          >
          > > I have been looking at JSON, and have seen in a few places where
          the
          > > eval statement is written
          > > x = eval('(' + var + ')');
          > >
          > > what is the purpose of the '(' and ')'
          >
          > In Javascript there is a potential syntactic ambiguity in which {...}
          > can be interpreted as either a block statement or an object literal.
          > The parens disambiguate.
          >
          OK. Thanks
          Could you give a simple example where this would fail? Would help to
          understand better
        Your message has been successfully submitted and would be delivered to recipients shortly.