Hi Tushar,
This is by design (and required by the standard). The reason is case
fallthrough, variables declared in one case block need to be visible in
others in case control flow falls through into them. Wrapping your case
bodies in {} is the usual workaround.
Cheers,
Leszek
On Mon, 6 Aug 2018, 06:58 , <[email protected]> wrote:
> Hello,
>
> I encountered a scenario and think it might be a potential bug. While
> declaring a variable inside the case in a switch statement, its scope is
> not just inside the case statement, it is for the whole switch statement.
>
> For eg. :
>
> switch(test){
>
> case test1 :
> let x =1;
> break;
>
> case test2 :
> let x = 2; * //error encountered. x already defined in the
> scope.*
> break;
>
> }
>
> Is it designed this way or is it a bug?
>
> Thnaks and Regards
> Tushar Khattar
>
>
> --
> --
> v8-dev mailing list
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
--
v8-dev mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.