JavaScript for WordPress Forums Gutenberg Development Preventing global scope and babel Reply To: Preventing global scope and babel

#40575
Zac Gordon
Keymaster

Hi there! Sorry for the delay on this. I wanted to first release my Vanilla JS Course, which delves deeply into state before I responded so if you wanted to dig deeper, resources were available to do so 🙂

But in short, global scope is the scope stored in the window object and available to all JS files that load on the same page.

When you write const and use imports, webpack will wrap the variables in global scope to prevent them from leaking into the global scope 🙂

Also, as browsers evolve, the conversion of const to var can become less needed.

Hope that helps!