1

I am using a pretty terrible library on the front-end. In their installation instructions, they tell to copy-paste some code, that starts with "use strict". And yet their code throws an error in some old browsers.

I am tempted to simply remove the "use strict" instruction from the code I have copy-pasted.

Is it safe though? Can it lead to a change of behaviour for the end user, apart from being more flexible?

The MDN article about strict mode states that Strict mode isn't just a subset: it intentionally has different semantics from normal code: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.

Vic Seedoubleyew
  • 9,888
  • 6
  • 55
  • 76
  • Removing strict-mode can lead to errors, yes. That doesn't mean it will, just that code that will throw on removing `"use strict;"` is possible. If you ask me, programming javascript in non-strict in 2022 is very, very questionable. – ASDFGerte Jan 10 '22 at 16:24
  • 1
    `use strict` is **not** about flexibility. JS by initial design is a very forgiving language. It will make some assumptions instead of throwing errors when you use illegal syntax. Obviously it's possible that side effects of such *automation* could produce undesirable outcomes. – PM 77-1 Jan 10 '22 at 16:27
  • strict-mode is a soft-deprecation of legacy features and behavior from the beginning of the web - esm was the next step, moving to strict-mode by default. If you want to have sleepless nights, because you've landed in the web-compat annex, good luck. PS: afaik even browsers from the stone age (IE11, not IE8, see https://caniuse.com/use-strict) support strict mode somewhat, but even for IE8, it was designed so it would be just an inert statement, in engines that don't support it. – ASDFGerte Jan 10 '22 at 16:35

0 Answers0