JavaScript Strict Mode Enforcement

In JavaScript, strict mode is enforced in modules but optional in regular programs. However, Lightning Web Security (LWS) and Lightning Locker implicitly enable JavaScript strict mode everywhere. You don’t need to specify "use strict" in your code. JavaScript strict mode makes code more secure, robust, and supportable.

When strict mode is enabled and unsafe actions are taken, JavaScript throws errors that would otherwise be suppressed. Examples of unsafe actions include assigning values to non-writable properties and using a variable that hasn’t been declared. Reporting these actions can catch situations when a variable name has been mistyped.

A few common stumbling points when using strict mode are:

For more information about JavaScript strict mode, see the Mozilla Developer Network.