Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL variable declaration and reference errors #22181

Closed
w1jp opened this issue Aug 7, 2018 · 3 comments
Closed

REPL variable declaration and reference errors #22181

w1jp opened this issue Aug 7, 2018 · 3 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. repl Issues and PRs related to the REPL subsystem.

Comments

@w1jp
Copy link

w1jp commented Aug 7, 2018

  • Version:
    v10.7.0

  • Platform:
    Darwin jMacBook.local 17.7.0 Darwin Kernel Version 17.7.0: Fri Jul 6 19:54:51 PDT 2018; root:xnu-4570.71.3~2/RELEASE_X86_64 x86_64

  • Subsystem:
    REPL

This has been happening a few releases and I am surprised no one has reported (that I could easily find) or fixed it. When declaring a variable with 'let' or 'const' and the literal contains an error, the system will not let me redeclare the variable or use it in an assignment. In the example below, I would have expected the REPL to merely ignore my declaration after giving me the error. I should then be free to redeclare it. However, it will not let me redeclare 'a' nor reference it for an assignment.

EXAMPLE:

jon@jMacBook:wrk$ node -v
v10.7.0
jon@jMacBook:wrk$ node
> let a = a
ReferenceError: a is not defined
> let a = 1
SyntaxError: Identifier 'a' has already been declared
> a = 1
ReferenceError: a is not defined
> 
@devsnek
Copy link
Member

devsnek commented Aug 7, 2018

this isn't really a bug. see #8309

@devsnek devsnek closed this as completed Aug 7, 2018
@devsnek devsnek added duplicate Issues and PRs that are duplicates of other issues or PRs. repl Issues and PRs related to the REPL subsystem. labels Aug 7, 2018
@w1jp
Copy link
Author

w1jp commented Aug 8, 2018

Thanks for the information-- Still a bug, but obviously a duplicate. As noted in the dialog, Babbel doesn't have this issue. Looks like its part of v8 as Safari and Chrome have the same behavior but Firefox still allows me to use the declared variable:

FIREFOX:
screen shot 2018-08-08 at 12 20 26
CHROME:
screen shot 2018-08-08 at 12 21 54
SAFARI:
screen shot 2018-08-08 at 12 21 38

@bounc3-paradise-on-e
Copy link

@w1jp

No, it's not a bug. The Node.js behavior is correct, according to the ES specification.

What you see in Babel is a Babel issue. What you see in Firefox is a gecko repl extension for devtools console. If you enable warnings in Firefox, you'll see this printed after evaluating your code:

Warning: According to the standard, after the above exception,
Warning: the global bindings should be permanently uninitialized.
Warning: We have non-standard-ly initialized them to `undefined`for you.
Warning: This nicety only happens in the JS shell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants