Strict Mode Settings In JavaScript Are Scoped To The Script Tag
CRANK

CAUTION: This is mostly a note to self.Yesterday, in a discussion with Sean Roberts, the lead of our Web Performance Team, I learned something new about the "use strict" mode assertion in JavaScript. Prior to our discussion, I had known that Strict Mode was scoped to Function blocks and to modules. But, I had assumed that if it were used inside of a Script tag, it would be scoped to the page in which the Script tag was included (just like every other reference in said Script tag). Sean pointed out that Strict Mode was, in actuality, scoped to Script tags as well. So, in attempt to burn this notable into the back of my mind, I wanted to see this scoping for myself.Run this demo in my JavaScript Demos project on GitHub.View this code in my JavaScript Demos project on GitHub.In order to determine whether or not a particular Script tag is running in Strict Mode, we can try to perform an illegal action and see if the JavaScript runtime throws an error. For example, in Strict Mode, you are …

bennadel.com
Related Topics: JavaScript GitHub Web Performance