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

693Order of Evaluation (OT?)

Expand Messages
  • mbrrtt
    Jun 22, 2009
      This may be slightly offtopic, but since the question relates to
      proper style and there are many JS experts in this group, I'm posing
      the question here.

      Can you rely on the order of evaluation of comma-separated
      initializing assignments in a 'var' statement? That is, can you rely
      on the order of evaluation being the same as the order in which the
      assignments are written? I can't find a clear answer in the ES-262
      spec, and it becomes germane because JSLint recommends a single 'var'
      statement per function.

      I'd like to write something like:

      var ...,
      defaultEpsilon = 1.0E-7,
      epsilon = defaultEpsilon,
      ... ;

      But since that would not work if the assignments were reversed and
      I'm not sure about the order of evaluation, I've been writing:

      var ...,
      defaultEpsilon = 1.0E-7,
      ... ;
      epsilon = defaultEpsilon;

      Does anyone know if I can count on the first version being ok, and if
      so, will that remain true for ES5?
    • Show all 4 messages in this topic