2

I have a script tag <script type="module" src="d.js"></script> and In that script tag I define a global variable like this df = 324. When I do this I get a reference error Uncaught ReferenceError: df is not defined. Why is this?

ethtrhaef
  • 57
  • 5

1 Answers1

4

Because modules are by default in strict mode

https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Strict_mode

If you try:

"use strict";
df = 324;

It wont work either

"use strict";
df = 324;

Without

df = 324;

console.log(df);
bill.gates
  • 14,145
  • 3
  • 19
  • 47