OPTING-IN
To opt-in to strict mode, use the strict mode pragma, which is simply a string that isn't assigned to any variable:
"use strict";
Using this syntax, which is valid even in ECMAScript 3, allows seamless fallback for JavaScript engines that don't support strict mode. The engines that support strict mode will enable it, while engines that don't will simply ignore the pragma as an unassigned string literal.
When the pragma is applied globally, outside of a function, strict mode is enabled for the entire script. That means adding the pragma to a single script that is concatenated with other scripts into a single file puts all JavaScript in the file into strict mode.
You can also turn on strict mode within a function only, such as:
function doSomething() {
"use strict";
// other processing
}
If you don't have complete control over all of the scripts on a page, then it's advisable to enable strict mode only within specific functions...