Is it a bug in firefox developer edition?
Asked Answered
T

1

16

Take a look at the below code:

var c = 50;

{
    console.log(y);
    let y = 50;
}

This code is expected to throw a ReferenceError and it does. But in the console, the message attached with the exception just blown my mind. It says:

ReferenceError: can't access lexical declaration 'c' before initialization

In the code c is the first variable declared. The error message indicates that something is wrong with the declaration of c. It's clearly the y variable inside the block, causing the exception. We can't use variables declared using let before its declaration. When I declare another variable in the first line, say test, the error message changes to:

ReferenceError: can't access lexical declaration 'test' before initialization

Am I missing something or am I right about the bug? I have the latest Firefox Developer Edition (version 49.0a2).

Another thing worth noticing is that the block is simply an enclosing block, it is not the body of a function.

Travelled answered 8/7, 2016 at 4:0 Comment(13)
@Kaiido So, it's a bug right? Because, Chrome has the expected error message for this case.Travelled
If you think it is a bug, than make a bug report and they will say yay or nay.Hebraic
@Bergi The error message confuses me because I thought it would say something is wrong with the variable 'y'. But instead, it says something is wrong with the variable that's on the first line in my example.Travelled
the bug exists in release version 47.0.1 as wellDisplume
Pushlog. Regressed by bug 589199 or 1202902.Magnificent
The minimal code would be var x; { y; let y; }Magnificent
Have you reported it yet?Magnificent
@Magnificent Nope! Not yet. More research is needed to know if this issue is big enough to be posted on bugzilla :)Travelled
@Devashish It's not a very important issue, but it definitely shouldn't behave like this. You can always inform of problems, the worst that can happen if they are not important enough is that nobody will fix them.Magnificent
@Magnificent okay, give me a day. I need to learn how to post bugs on the forum. It is going to be my first post.Travelled
@Magnificent I reported the bug. Here is the link: bugzilla.mozilla.org/show_bug.cgi?id=1285710Travelled
I see the bug 1285710 is marked as fixed in Firefox 53 on their bug trackerRayraya
Yes I tested this in version 54.0a2 and see ReferenceError: can't access lexical declaration 'y' before initialization. I am voting to close this because it can't be reproduced anymore.Bobseine
N
1

This post is made in accordance with this meta post, instead of being closed (see this).


As @Martin Smith and @Sam Onela said (1, 2), this issue was resolved in version 53/54. Relevant bugzilla report, made by Devashish (original poster).

Nectarine answered 8/7, 2016 at 4:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.