Home Next »

Use Strict

Use Strict === Strict Operating Context

We can enable strict mode by placing the below string on top of a file, or using it within your function.

"use strict"

Note: If you notice, use strict is not a keyword, its just a string. This is because, when this feature was thought, the older browsers didn’t supported. Hence it was introduced as a string. So the older browsers could simply ignore it treating it as a string.

Is it possible to have strict mode partially in your application?

Yes! It is possible. Simply place the “use strict” inside your function definition.

// Not in strict mode
function newFunction(){
"use strict";
// strict mode
}

To validate this further, please copy paste the below snippet in your browser console.

foo = 10;
function strictArea() {
"use strict"
    moo = 20;
}
Home Next »