1000Nettles
1000Nettles

Reputation: 2334

Is Strict Mode isolated to individual JavaScript files?

When including 'use strict'; at the beginning of a JavaScript file which is included in an HTML page, would any subsequent included files or JS adhere to the Strict Mode ruling established in the first file? Or would Strict Mode be isolated to the first file?

Example:

<script src="/path/to/file_using_use_strict.js"></script>
<script src="/path/to/file_omitting_use_strict.js"></script>
<script>
  console.log('Hello! Am I strict?');
</script>

I checked the MDN documentation, but couldn't find an example outlining this specific situation. Thanks!

Upvotes: 0

Views: 153

Answers (1)

benvc
benvc

Reputation: 15130

From the Strict mode MDN web docs:

Strict mode applies to entire scripts or to individual functions.

So the answer to your question is yes, strict mode only applies to the scripts or functions where you invoke it.

Upvotes: 3

Related Questions