I think I got it, var has only global and function scope, this means x and y are in fact in the same scope, they are collected into the environment when the function body is evaluated. (https://262.ecma-international.org/#sec-functiondeclarationinstantiation step 9)
function test() { var x { var y } } 在2023年7月7日星期五 UTC+8 17:32:59<Marja Hölttä> 写道: > You'll probably want to check out "Static semantics: > VarScopedDeclarations" ( > https://262.ecma-international.org/#sec-static-semantics-varscopeddeclarations > > ) and its usage in > https://262.ecma-international.org/#sec-globaldeclarationinstantiation . > Let us know if that didn't help (or if it did) :) > > > > > On Fri, Jul 7, 2023 at 9:58 AM Shang Yu <yus...@gmail.com> wrote: > >> Hi guys, >> I'm reading 14.3.2.1 >> <https://262.ecma-international.org/#sec-variable-statement-runtime-semantics-evaluation> >> section >> of ecma232 and trying to find out how the following code is evaluated. >> *var x *// A >> according to the following part of 14.3.2.1 >> >> VariableDeclaration : BindingIdentifier >> 1. Return empty. >> >> It seems the code at line A will be a non-op, that is it will do nothing. >> If this is right, the following code should not run in my understanding, >> but it did run, how does this happen? Many thanks ! >> >> ‘use strict’ >> var x >> x=0 >> >> -- >> -- >> v8-dev mailing list >> v8-...@googlegroups.com >> http://groups.google.com/group/v8-dev >> --- >> You received this message because you are subscribed to the Google Groups >> "v8-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to v8-dev+un...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/v8-dev/d20e9269-8ee5-4030-a342-20ee1887078en%40googlegroups.com >> >> <https://groups.google.com/d/msgid/v8-dev/d20e9269-8ee5-4030-a342-20ee1887078en%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > > Google Germany GmbH > > Erika-Mann-Straße 33 > > 80636 München > > > Geschäftsführer: Paul Manicle, Liana Sebastian. > > Registergericht und -nummer: Hamburg, HRB 86891 > > Sitz der Gesellschaft: Hamburg > > > Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten > haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, > löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, > dass die E-Mail an die falsche Person gesendet wurde. > > > > This e-mail is confidential. If you received this communication by > mistake, please don't forward it to anyone else, please erase all copies > and attachments, and please let me know that it has gone to the wrong > person. > > -- -- v8-dev mailing list v8-dev@googlegroups.com http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/7fb0d6f9-c38c-4884-8a82-55d0094c2668n%40googlegroups.com.