‘use strict’ in Javascript

‘use strict’ is literal expression which was introduced in ECMAScript 2015.

Basically, when you use ‘use strict’ it tells the Browser to execute code into ‘Strict mode’.

When you mention ‘use strict’ it won’t allow you to use undeclared variable into code.. it will throw an error and you can see the same into Developer console.

Strict mode is declared by adding “use strict”; to the beginning of a script or a function.

Note:  The “use strict” is only recognized at the beginning of a script or a function.

Below are the operations which are not allowed in Strict mode.

  1. You can not use Variable without declaring it.
  2. You can not use Object without declaring it.
  3. Deleting Object/Function/variable is not allowed in Strict mode.
  4. Duplicate parameter names are not allowed.
  5. Writing of read only properties are not allowed.
  6. Keywords which are reserved for future of Javascript is not allowed to use, it will throw error.
  7. ‘eval’ can not be used as variable/object name

How to use strict mode.


 "use strict"; 

at the beginning of Javascript file or function.

Join Discussion

This site uses Akismet to reduce spam. Learn how your comment data is processed.