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.
- 3You could have searched for it and got the answer sooner. stackoverflow.com/questions/1335851/…Jehanzeb.Malik– Jehanzeb.Malik2013-02-15 07:31:47 +00:00Commented Feb 15, 2013 at 7:31
Add a comment |
2 Answers
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:
- Some errors are no longer silent and throw instead.
- Allows the interpreter to make optmizations.
- Prohibits syntax that will likely be deprecated in the next version of ECMAScript.
3 Comments
PiTheNumber
IE10 is the first IE that supports strict mode: caniuse.com/#feat=use-strict
Esteban Araya
@PiTheNumber This is why Douglas Crockford said: "IE9 must die too. But IE10 may live." :)
PiTheNumber
By the time IE10 has reached the normal user, there will be many other features IE10 does not support. ;)
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.