3

Is there any reason why I should consider not using 'use strict' in a node module published via npm? Is it 'safe' to do that if I want others to be able to use it?

EDIT: I asked this question explicitly to find out, if it can make the module useless/broken for anybody who wants to install it via npm.

Florian Wendelborn
  • 1,667
  • 1
  • 19
  • 29
  • Duplicate: http://stackoverflow.com/questions/18417381/in-node-js-how-the-use-strict-statement-is-interpreted – Andrey Popov May 28 '15 at 19:35
  • Is it really a duplicate? I was explicitly asking for any compatibility reasons when I publish a module via npm. – Florian Wendelborn May 28 '15 at 19:43
  • 1
    Well read how and why you can/should use it and what does it mean. Then you will simply understand where to and not to use it. It's very simple, you just need to read it. – Andrey Popov May 28 '15 at 19:45
  • I see you won't do any effort, but I can tell you that there is an accepted answer (with 35 score) that has **exactly** what you're searching for! :) – Andrey Popov May 28 '15 at 19:47
  • 1
    AFAIK 'use strict' is scoped to your module, (or even specific functions, if you like). I shouldn't need to know/care if you used 'use strict' in order to use your module, as long as your module works. – Raphael Serota May 28 '15 at 19:47
  • 1
    IF this were a dupliclate, surely http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it would be a better candidate. (I do not think this is a duplicate of either, though, knowing the information from either should be enough to answer the question.) – Kevin B May 28 '15 at 19:48

1 Answers1

6

'use strict'; enforces a set of rules on your code. If ran in an environment that doesn't support 'use strict';, it is simply ignored, no harm done.

It will only apply to your code, assuming it is not concatenated with anyone else's code (unless you're using it inside of a function rather than outside, in which case it would only affect that function, even if concatenated.)

Therefore, Yes, it is safe to use 'use strict'; in a piece of code without fear of it causing problems for other people using your code. I would even go as far as saying it is recommended.

Kevin B
  • 94,570
  • 16
  • 163
  • 180