Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Phasers locked on target, Captain.


devel / comp.lang.javascript / Re: Javascript Scope Related Doubt

SubjectAuthor
* Javascript Scope Related DoubtGaurav Kumar Arya
`- Re: Javascript Scope Related DoubtJulio Di Egidio

1
Javascript Scope Related Doubt

<5d92dd79-888f-4f85-a686-21cbc90e945cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17209&group=comp.lang.javascript#17209

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:622a:489:: with SMTP id p9mr8103247qtx.256.1628243629554;
Fri, 06 Aug 2021 02:53:49 -0700 (PDT)
X-Received: by 2002:a9d:7a99:: with SMTP id l25mr3432182otn.69.1628243629121;
Fri, 06 Aug 2021 02:53:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Fri, 6 Aug 2021 02:53:48 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=180.151.28.74; posting-account=zDZEUwoAAAAnAImBaaz1tA0FnTrdhA1S
NNTP-Posting-Host: 180.151.28.74
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5d92dd79-888f-4f85-a686-21cbc90e945cn@googlegroups.com>
Subject: Javascript Scope Related Doubt
From: gauravmka24@gmail.com (Gaurav Kumar Arya)
Injection-Date: Fri, 06 Aug 2021 09:53:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Gaurav Kumar Arya - Fri, 6 Aug 2021 09:53 UTC

Hello Sir/Madam,

I have one doubt regarding this question
(function fn() {
{
let a = 10;
{
var a = 20;
console.log(a);
}
} })();

why it is giving syntax Error ?
I know this is illegal shadowing concept but when I put braces before let a =10, then that a variable has block scoped and var a is function scoped, here after adding curly braces before let a , I have create new scope and after fn(){ // here var a is hoist}, then if both are in different scope , why it is showing error.

Please help in explaining this concept.

Thank You

Re: Javascript Scope Related Doubt

<36b8dbb4-36d0-4b26-963c-d819a667df2bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17210&group=comp.lang.javascript#17210

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:622a:1105:: with SMTP id e5mr8557040qty.268.1628246062699;
Fri, 06 Aug 2021 03:34:22 -0700 (PDT)
X-Received: by 2002:a4a:e9a8:: with SMTP id t8mr6199381ood.59.1628246062442;
Fri, 06 Aug 2021 03:34:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Fri, 6 Aug 2021 03:34:22 -0700 (PDT)
In-Reply-To: <5d92dd79-888f-4f85-a686-21cbc90e945cn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=93.41.96.50; posting-account=F3H0JAgAAADcYVukktnHx7hFG5stjWse
NNTP-Posting-Host: 93.41.96.50
References: <5d92dd79-888f-4f85-a686-21cbc90e945cn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <36b8dbb4-36d0-4b26-963c-d819a667df2bn@googlegroups.com>
Subject: Re: Javascript Scope Related Doubt
From: julio@diegidio.name (Julio Di Egidio)
Injection-Date: Fri, 06 Aug 2021 10:34:22 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Julio Di Egidio - Fri, 6 Aug 2021 10:34 UTC

On Friday, 6 August 2021 at 11:53:53 UTC+2, gaura...@gmail.com wrote:
> Hello Sir/Madam,
>
> I have one doubt regarding this question
> (function fn() {
> {
> let a = 10;
> {
> var a = 20;
> console.log(a);
> }
> }
> })();
>
> why it is giving syntax Error ?
> I know this is illegal shadowing concept but when I put braces before let a =10, then that a variable has block scoped and var a is function scoped, here after adding curly braces before let a , I have create new scope and after fn(){ // here var a is hoist}, then if both are in different scope , why it is showing error.

They are not in a different scope: "let a" is in the *top* block scope of the function, which is the entire function, but so is "var a", as that's how var scoping works.

> Please help in explaining this concept.

Have a read through this and related:
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let>
The very last example is your case.

HTH,

Julio


devel / comp.lang.javascript / Re: Javascript Scope Related Doubt

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor