Repository navigation
let assigment breaks typeof #33462
Description
Activity
- addedv8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.and removedv8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.
on May 19, 2020 Duplicate of #8309, albeit a much more confusing one.
- addedduplicateIssues and PRs that are duplicates of other issues or PRs.Issues and PRs that are duplicates of other issues or PRs.replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.
on May 19, 2020 Also, you've technically found a bug in firefox. If you feel like it you can report it here: https://bugzilla.mozilla.org/
@mariorodriguespt it should be throwing in firefox. This is the same case as
{ typeof x; let x; }It is not throwing on Firefox and it is correct.
It throws an error when you trylet a = a || 2but thetypeofworks as expected.On your example, Firefox does throw an error:
ReferenceError: "can't access lexical declarationx' before initialization"` which is correct due to the order.As far as I can tell, V8 is not handling this correctly: The assignment failed but the
typeofgot broken, this issue is more relevant on a browser environment where you have a second script checking a var usingtypeof.When you do
let x = /* something that throws an error */, the variable is created, but is never initialized. This state is called the "temporal dead zone" (https://snek.dev/blag/2019-07_js_hoisting might help). While a variable is in the temporal dead zone,typeof xwill throw, because the variable exists and is resolvable, but getting its value to try to get the type of it throws a reference error. V8 is behaving correctly here, and firefox has a bug.Just opened a bug on Firefox, I'll leave the link for those interested in the follow up: https://bugzilla.mozilla.org/show_bug.cgi?id=1639078

What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Every single time. If you use
letto define a variable and in the assignment part you check if the same variable exists, you won't be able to usetypeofafter.What is the expected behavior?
I would expect
typeofshould always work regardless of the variableaexisting or not.What do you see instead?
Uncaught ReferenceError: a is not defined
Additional information
This appear to be an issue in Chromium since it works as expected in Firefox.