DEV Community

Discussion on: Don't name your global JavaScript function 'clear'

Collapse
 
josephthecoder profile image
Joseph Stevens

Arghh, that isn't okay! That is not okay. I know a bunch of other tools and languages have the same issue of reserved keywords.
But like, a lot a lot of at least throw a warning! Not just...
Shrug, I'll just do nothing. You need to learn my super duper interesting scoping mechanics! Gah. I've been doing JavaScript for like 8 years now, I am so tired of learning new things and surprising JavaScript mechanics

Collapse
 
nikola profile image
Nikola Brežnjak

It does get frustrating, I'll give you that. However, our best option is to embrace it and get around it the best we can 💪

Collapse
 
josephthecoder profile image
Joseph Stevens

I respect your opinion, but that is absolutely not the best option.
The best option is to make reserved keywords illegal to the compiler/linter.

Aka.
function clear() {...}
Would not compile, or the editor would turn the line red.
At the very least, mark it as a warning.