Newer Version Available
JavaScript Strict Mode Enforcement
Lightning Locker implicitly enables JavaScript strict mode. 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 are otherwise 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:
- You must declare variables with the var or let keyword.
- You must explicitly attach a variable to the window object to create a global variable that’s available across components or libraries. For more information, see Sharing JavaScript Code Across Components.
- The libraries that your components use must also work in strict mode.
For more information about JavaScript strict mode, see the Mozilla Developer Network.