JS ES5 "use strict"
May 22, 2020 by Jane

Javascript is one of those languages, that after learning C++ or C, one might find too casual or forgiving. No fear. Strict mode is here. Simply put "use strict"; at the top of the function or script and the browser will do the rest. This feature is available IE10 and later.

 

A summary of what strict mode prohibits.

1) Variables used before they are declared

2) Deleting variables and functions or undeletable properties such as "prototype"

3) Duplicating parameter names

4) Octal numerals and escape characters (numbers prefixed by 0 or \0)

5) Writing to read-only object property indicated by writable:false or get-only property

E.g. var obj = {}; Object.defineProperty(obj, "x", {value:0, writable:false}); obj.x = 3.14; is illegal

E.g. 2. var obj = {get x() {return 0} }; obj.x = 3.145; is illegal (this is similar to C#)

6) "eval", "arguments","public", "private" etc are keywords or potential keywords and cannot be used as variable name. eval() also cannot create variables.

7) "with" expressions are not allowed

8) "this" keyword is undefined unless specified