Skip to content
Browse files

adds new wiki - JS-Strict-Mode.md

  • Loading branch information...
1 parent cb49b7c commit c703aef0da58f6ab9d7eb3e6ebe0ac7bafca5abe rishipuri committed
Showing with 47 additions and 0 deletions.
  1. +47 −0 JS-Strict-Mode.md
View
47 JS-Strict-Mode.md
@@ -0,0 +1,47 @@
+# 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...
+
+### Invoking strict mode
+
+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](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Strict_mode).*

0 comments on commit c703aef

Please sign in to comment.
Something went wrong with that request. Please try again.