Undefined Variable Declaration


#1

Hello, I have the code: const queue = new Map();

But Map is undefed. Can anyone help?


#2

It’ll just be a linter warning. So long as the code is valid, it will still work.

You can specify global variables at the top of your file to make this warning go away - see https://eslint.org/docs/user-guide/configuring#specifying-globals


#3

Hello @Gareth,

Linter errors due to Specifying Globals can be confusing for beginners who just learned how to use libraries.

From a pedagogical point of view, shouldn’t this rule (or maybe all linter rules) be turned off on a beginner friendly platform like Glitch?

Linter errors could still be activated with a .eslintrc file.


#4

We’ve since updated our linting rules so this specific issue should no longer be a problem - my response was a work around useful at the time of posting.

However, I’m interested to understand more about that perspective. Globals aside, linting would seem to be useful for beginners to reinforce learning correct syntax and avoiding confusing runtime issues resulting from incorrect syntax.


#5

Hello Gareth,

it seems this rule is still active: see https://glitch.com/edit/#!/hello-ml5js?path=script.js:4:66


This is weird since i had no errors with jQuery on different examples.

Globals aside, linting would seem to be useful for beginners to reinforce learning correct syntax and avoiding confusing runtime issues resulting from incorrect syntax

Agree, yet i believe that only true errors preventing running the script (like forgetting a ; in a for loop, or a } in a css file ) should show an error hint, while ESLint could show a warn hint.
This way beginners would know about their errors and could also learn about “best practices”.

More over, ESLint messages can be confusing: in the case of the Specifying Globals rule ‘XXX’ is not defined, beginners don’t understand that the message is in the context of this script (I imported my XXX correctly in my html file, why is XXX not found?). Message warning could be “XXX is not defined in this script”.

Initiatives like Processing and p5.js are doing great work on trying to make errors more understandable for beginners: Friendly Error System for p5.js

Re-thinking ESLint messages could add even more friendliness to the already friendly platform that Glitch is.


#6

I was referring specifically to the Map issue. But thanks for taking the time to provide that feedback. I’ll share it with the team to talk through!


#7

This issue with Specifying Globals rule iseven more flagrant when using p5js: https://glitch.com/edit/#!/p5js-hello-p5-animation?path=sketch.js:2:9