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.
Asked
Active
Viewed 1,562 times
25

Eric
- 95,302
- 53
- 242
- 374

Tepken Vannkorn
- 9,648
- 14
- 61
- 86
-
3You could have searched for it and got the answer sooner. http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it – Jehanzeb.Malik Feb 15 '13 at 07:31
2 Answers
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:
- 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.

Esteban Araya
- 29,284
- 24
- 107
- 141
-
1IE10 is the first IE that supports strict mode: http://caniuse.com/#feat=use-strict – PiTheNumber Feb 15 '13 at 07:35
-
2@PiTheNumber This is why Douglas Crockford said: "IE9 must die too. But IE10 may live." :) – Esteban Araya Feb 15 '13 at 07:35
-
By the time IE10 has reached the normal user, there will be many other features IE10 does not support. ;) – PiTheNumber Feb 15 '13 at 07:39
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.

Quentin
- 914,110
- 126
- 1,211
- 1,335