You should use strict mode everywhere, but what about inherited code?
Typically, you designate strict mode at the beginning of the module -
|
|
But the module and its friends may have millions of lines of code that you did not write and do not have time to fix. If you introduce "use strict"
globally (i.e., at the beginning of the module), you start seeing all those errors here and now.
Well, lucky for us - strict mode was designed to be used incrementally.
Strict mode can be included only at the beginning of the module or function.
|
|
|
|
So, all you need to do is make two rules (and tinker with your ESLint to enforce those rules) -
- Any new module must have
"use strict";
at the beginning of the module - Any new function within existing module should have
"use strict";
. If it cannot be done, avoid creating new functions in the said module
Ensure that all developers understand and appreciate how errors are thrown with and without strict mode, so that they don’t tear themselves apart by all the inconsistent errors popping up during debugging and in production.