3

I'd appreciate your lessons learnt through experience on when to and when NOT to, "use strict" in Javascript.

IMHO, "use strict" is good in server-side javascript code but NOT client-side, because not all (even modern) browsers support this feature. Correct?

karthiks
  • 7,049
  • 7
  • 47
  • 62
  • My personal PoV on this (which is by no means correct) is that `use strict` is for [expletive]s who can't write code without the browser shouting YOU ARE WRONG at them for every mistake. – Niet the Dark Absol Feb 07 '14 at 07:59
  • 1
    @NiettheDarkAbsol so I suppose you write all your code in Notepad? Why use things like a modern IDE to help you find errors, why use things like code completion? Heck, why even use a high level language. Just write assembly! – Wouter de Kort Feb 07 '14 at 08:01
  • 1
    Related: [What does “use strict” do in JavaScript, and what is the reasoning behind it?](https://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it) –  Feb 07 '14 at 08:01
  • @WouterdeKort Typical response XD FYI, I used Notepad for many, many years and it suited me just fine. Now I use Notepad++ but most of the time I just treat it like "Notepad with colours". By writing code in such a raw and primitive manner, it forces me to *pay attention*. – Niet the Dark Absol Feb 07 '14 at 08:03
  • I found this interesting article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode – adripanico Feb 07 '14 at 08:03
  • @NiettheDarkAbsol respect ;) – Wouter de Kort Feb 07 '14 at 08:04
  • @JonathonReinhart In continuation to my previous comment, because I am forced to pay attention, I make fewer errors. Heck, I have written PHP on my Nintendo DS in the past due to circumstances. – Niet the Dark Absol Feb 07 '14 at 08:04
  • @NiettheDarkAbsol So if you make so few errors, you would rarely be bothered by the `use strict`, no? I find your logic to be of the utmost nonsense. A C compiler is pretty good at forcing you "to pay attention". – Jonathon Reinhart Feb 07 '14 at 08:05
  • There is a reason I disclaimed my opinion as "by no means correct". It's my opinion, and it's based on my pig-headed "Javascript 1.2 was good enough for me" general attitude. Heck, I still write `for` loops instead of using `[].forEach` most of the time even when I know all users have supporting browsers, simply on the principle that I can add a `break` at any time later without rearranging the code. – Niet the Dark Absol Feb 07 '14 at 08:13
  • Seriously, I fail to understand the intention of putting this question on hold. I'm so explicit in asking for lessons learnt in using it. And so far, folks have answered their mind with some reference. I'm hating this action of your guys..do give a read to the question a read and thought before taking action. – karthiks Feb 07 '14 at 15:04

2 Answers2

2

Read this john resig on strict mode

"use strict"; is as important in client side javascript programming as in server's.

If it is not supported by a browser it would do no harm as it is just a string plus a semicolon .. which would do nothing if not recognized correctly by an interpreter.

With "use strict"; mode .. if your program runs correctly even in one of the modern browsers like chrome then you now know that your program does not have any silly errors. After that you are good to go on any other possible browser because as I said it would do no harm if not interpreted correctly.

TwiToiT
  • 1,200
  • 2
  • 9
  • 13
-1

yeah, thats right. But some browser not supported.

Actually, a lot of modern browser supported use-strict.

        Internet Explorer = v10,v11
        Firefox           = v4.0 +
                **Webkit** 
        Chrome            = v13.0 +
        Opera             = v11.6 +
        Safari            = v6.0 + 

check it please : http://caniuse.com/use-strict

mehmetakifalp
  • 445
  • 5
  • 16