LoginSignup
3

More than 5 years have passed since last update.

"use strict"は他のファイルには影響しない

Posted at

"use strict"と関数内の始めに書くとその関数内でStrictモードが有効になる。関数の外に書いた場合、他のファイルにも影響が出ると思いきや、どうやらそのファイル内でのみ有効になるらしい。

ケース1

index.html
<script src="script.js"></script>
script.js
"use strict";
a = 0; // Uncaught ReferenceError: a is not defined

ケース2

index.html
<script src="script1.js"></script>
<script src="script2.js"></script>
script1.js
"use strict";
script2.js
a = 0; // エラーにならない

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3