-
Notifications
You must be signed in to change notification settings - Fork 2
JS Strict Mode
Strict Mode was introduced in ECMAScript 5 that allows you to place a program, or a function, in a "strict" operating context. This strict context prevents certain actions from being taken and throws more exceptions.
Strict mode makes several changes to normal JavaScript semantics.
- First, strict mode eliminates some JavaScript silent errors by changing them to throw errors.
- Second, strict mode fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that's not strict mode.
- Third, strict mode prohibits some syntax likely to be defined in future versions of ECMAScript.
Strict mode code and non-strict mode code can coexist in a same script.
// Non-strict code...
(function(){
"use strict";
// Define your library strictly...
})();
// Non-strict code...
Strict mode applies to entire scripts or to individual functions.
Strict mode for scripts
// Whole-script strict mode syntax
"use strict";
var v = "Hi! I'm a strict mode script!";
Strict mode for functions
function strict(){
// Function-level strict mode syntax
'use strict';
function nested() { return "And so am I!"; }
return "Hi! I'm a strict mode function! " + nested();
}
function notStrict() { return "I'm not strict."; }
Basically it helps you make fewer errors, by detecting things that could lead to breakage which are not detected normally (non-strict mode).
For more information check out this MDN page.
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links