Nearly all my JS files are wrapped in anonymous functions. If I include "use strict"; outside the anonymous function, is strict mode still applied to the anonymous function?
For example, is strict mode applied to the inner body of the anonymous function in the script below:
"use strict";
(function() {
// Is this code running under strict mode?
})();
According to John Resig’s article, if you turn on strict mode at the top of the file, it applies to the entire file/script. So yes, that implies that it would apply within the anonymous function.
You can also add it within a function, in which case it only applies to that specific function.
Edited to add: here’s the full specification. One relevant paragraph: