Benefits of "Use Strict" in JS

JavascriptUse Strict

Javascript Problem Overview


What are the additional benefits of "use strict" other than preventing bad coding? For instance, does it allow the script to run faster because the interpreter knows the code its optimized?

Javascript Solutions


Solution 1 - Javascript

There are a zillion benefits to strict mode, but since you asked specifically about performance, not just the good coding benefits, here's what MDN says about that:

> 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.

So as you asked, according to the Firefox folks at MDN, strict mode code can sometimes run faster.

For general benefits of strict mode, see https://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it

Solution 2 - Javascript

Here are the benefits :)

  1. Duplicate keys in object.
  2. Variables without var
  3. Duplicate arguments
  4. Freezes the arguments of the functions

See a better explanation of Use strict in JavaScript here.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTMacGyverView Question on Stackoverflow
Solution 1 - Javascriptjfriend00View Answer on Stackoverflow
Solution 2 - JavascriptmsapkalView Answer on Stackoverflow