Is not defined and identifier has already been declared at the same time
Asked Answered
E

2

8

In chrome devtools if I first try to declare a variable but the operation fail (see example below I'm trying to assign to a not defined variable), then I get following behaviour: I'm not able to assign to the variable because of the ReferneceError at the same time I'm not able to declare it because of the SyntaxError. See screen below.

The following seems a bit illogical to me. Could someone explain?

I'm using Chrome Version 55.0.2883.95 (64-bit) on OS X El Capitan.

enter image description here

Euchology answered 30/12, 2016 at 12:1 Comment(4)
Seems like a bug. Can you file a bug at crbug.com?Toddler
You're inside a use strict context, so every error message on your screenshot is correct.Jarrett
+w0xx0m This is not a use strict context. The console works in non-strict mode. let/const identifiers have been applicable there for some time.Fulfillment
The console works in current context, which may be different depending on whether the debugger is paused inside use strict scope.Jarrett
F
1

Testing this in Firefox I am seeing it function as you'd expect. Where you can later set x = 2; just fine. Please file a bug on the chromium bug tracker so the Chrome team can triage this and get it working.

Thank you.

firefox-define-ref-error

Fulfillment answered 1/1, 2017 at 11:57 Comment(0)
B
0

Unfortunately this is to spec, see for example https://github.com/nodejs/node/issues/8309. Frustrating behaviour for a REPL, but not actually a bug.

The Firefox devtools set the problem variable to undefined in such cases instead of leaving that variable name unusable, but this is non-standard behavior and is not implemented in Chrome.

Buffum answered 5/1 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.