about 14.3.2.1 section of ecma262

27 views
Skip to first unread message

Shang Yu

unread,
Jul 7, 2023, 3:58:37 AM7/7/23
to v8-dev
Hi guys,
I'm reading 14.3.2.1 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

Marja Hölttä

unread,
Jul 7, 2023, 5:32:59 AM7/7/23
to v8-...@googlegroups.com
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) :)




--
--
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.


--

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.


Message has been deleted

Shang Yu

unread,
Jul 7, 2023, 10:45:42 PM7/7/23
to v8-dev
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
  }
}

Reply all
Reply to author
Forward
0 new messages