mode javascript code example

Example 1: javascript use strict

// Whole-Script Strict Mode Syntax
'use strict';
var v = "Hi! I'm a strict mode script!";

Example 2: use strict javascript

// File: myscript.js

'use strict';
var a = 2;
....

Example 3: use strict javascript

// Non-strict code...

(function(){
  "use strict";

  // Define your library strictly...
})();

// Non-strict code...

Example 4: strict mode

Strict mode makes several changes to normal JavaScript semantics:
-Eliminates some JavaScript silent errors by changing them to throw errors.
-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.
-Prohibits some syntax likely to be defined in future versions of ECMAScript.