1

I have been looking for a while to understand how good is to use the 'use strict', however till IE10 comes up its still in debate but putting that aside, i really want to understand how browser interprets the 'use strict' stmt. Reason i said interprets is wanted to understand will is slow at runtime or not.

If it is used as early catch mechanism to improve code & performance why we need to declare it in js files. Why not use jlint & other external tools to help fix code, errors & improve performance. Just like we use findbugs & other tools in eclipse to fix java related why not for JS. Bigger question is will browser or become too cautious when it see the strict word then better get on with external tools like jslint. I did refer below link where in 'sunspider' site is given example but not sure it is exceptional or really browser exection does not changes on seeing strict word & so its it performance does not degrade.

Is strict mode more performant?

Community
  • 1
  • 1
user593029
  • 511
  • 7
  • 18
  • Strict mode *improves* performance; in fact that's a major reason for its existence. There's no reason at all not to use "use strict" in your code. – Pointy Aug 23 '12 at 16:03
  • has any one done before & after comparision at **runtime** to see how browser performs. It's my guess that browser might perform different or interpret more stringently when it reads "use strict". That is i am trying to highlight use external tools which does similar thing to improve performance, errors & improve js code, so that no need hardcode "use strict" in every js file & above all if browser have **to burn extra cycle to interpret code differently & degrade performance** in terms of cycle (its not about developer pain & best practice here am taking about browser stand point) – user593029 Aug 23 '12 at 16:49
  • The work done by the JavaScript runtime to parse the code is a nearly-trivial factor in page performance, strict mode or not. Once the code is parsed, then it absolutely doesn't matter. It's really pointless to worry about something like this. If you have a performance problem, see if removing `"use strict";` helps (it won't), but until then it's a non-issue. – Pointy Aug 23 '12 at 16:56
  • IE causes issues with the 'use strict', till IE10 comes support is not there (basically trial & error). Also safari & other do support is just **partial** not full. So it can cause cross browser issue worth talking when external tools are available. The statement "JavaScript runtime to parse the code is a nearly-trivial factor in page performance" in **certain scenario** still stands correct when we 'use strict' is worth finding. But thanks for sharing. Will update all i if something found reasonable to share. – user593029 Aug 23 '12 at 17:23
  • "use strict" works perfectly well in old versions of IE because it has no effect whatsoever. – Pointy Aug 23 '12 at 17:25
  • check out below ECMAScript5 comparison for 'use script' it does not say so http://kangax.github.com/es5-compat-table/ – user593029 Aug 23 '12 at 17:32
  • It doesn't do anything special when "use strict" is present, but it also doesn't cause any problems. In other words, adding "use strict" to a script will have no effect in Internet Explorer. – Pointy Aug 23 '12 at 17:40

1 Answers1

1

There is no reason you can't use "use strict" and jsLint / jsHint together to check the quality of your code. The difference is, strict mode uses established JavaScript / ECMAScript 5 standards that the community has agreed on, when code quality tools, such as jsLint, are more opinionated (ahem Douglas Crockford). Here is a post by John Resig describing strict mode:

John Resig on Strict Mode

If you are interested about performance, I created a jsPerf test that tests my jQuery plugin, Tocify, with and without strict mode. The performance was the exact same.

Greg Franko
  • 1,780
  • 15
  • 14
  • I do understand we can use both but at runtime will it affect the browser performance or not that is what i am trying to figure. I read & research most forum they do advice it is best practice to use "use strict" but using jslint if we can achive the same why to declare in "use lint" **above all when the browser looks the stmt "use strict" will it affect the performance of browser in any way that is the real question** If the browser interpretation to java code becomes more stringent & perf degrades its better to rely external tools. Has any done before & after strict option to see the perf. – user593029 Aug 23 '12 at 16:39
  • Just added a sample jsPerf test. – Greg Franko Aug 23 '12 at 18:47