25

I have been reading many JavaScript codes recently and I was wondering of what are the benefits of using "use strict". Any idea would be very much appreciated.

1

2 Answers 2

12

Before you go and put "use strict" on all your scripts, a warning:

Browsers that do not support strict mode, will run your code with different behavior from browsers that do.

Now, to answer your question. The benefits of strict mode are:

  1. Some errors are no longer silent and throw instead.
  2. Allows the interpreter to make optmizations.
  3. Prohibits syntax that will likely be deprecated in the next version of ECMAScript.

(Source: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode)

Sign up to request clarification or add additional context in comments.

3 Comments

IE10 is the first IE that supports strict mode: caniuse.com/#feat=use-strict
@PiTheNumber This is why Douglas Crockford said: "IE9 must die too. But IE10 may live." :)
By the time IE10 has reached the normal user, there will be many other features IE10 does not support. ;)
2

It activates strict mode (where supported). The main benefits are that some silent errors and some coding practices that can trip you up are turned into loud errors so you can avoid them entirely.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.