What does ‘use strict’ do and what are some of the key benefits to using it?

Including 'use strict' at the beginning of your JavaScript source file enables strict mode, which enforces more strict parsing and error handling of JavaScript code. It is considered a good practice and offers a lot of benefits, such as:

  • Easier debugging due to eliminating silent errors.
  • Disallows variable redefinition.
  • Prevents accidental global variables.
  • Oftentimes provides increased performance over identical code that is not running in strict mode.
  • Simplifies eval() and arguments.
  • Helps make JavaScript more secure.

Extra Info

  • Eliminates this coercion, throwing an error when this references a value of null or undefined.
  • Throws an error on invalid usage of delete.
  • Prohibits some syntax likely to be defined in future versions of ECMAScript
Additional links

Leave a Reply

Your email address will not be published. Required fields are marked *

*