---
schema_version: "1"
id: ab1865c56377e877d02c93424c31e97818494602fe404228afa456f3154542ae
title: JavaScript Strict Mode Enforcement
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/lwc/lightning-components-security/guides/js/js-strict-mode-intro.md
canonical_url: https://developer.salesforce.com/docs/platform/lightning-components-security/guide/js-strict-mode-intro.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5ae6ec151c9a2bd70eed9fab0600944dc84100d8b0daadf0f86a64843e408613
products:
  - Security for Lightning Components
  - lwc
---
# 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:

- You must declare all variables. Use any of the `var`, `let`, or `const` declarations in libraries or modules.
- To share code between components, you must follow the steps outlined in [Share JavaScript Code](/docs/platform/lwc/guide/js-share-code.html) for Lightning web components and [Sharing JavaScript Code Across Components](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_share_code.htm) for Aura components, respectively.
- The libraries that your components use must also work in strict mode but don’t need to specify `"use strict"` in their own code. For developing Lightning web components, see [Use Third-Party JavaScript Libraries](/docs/platform/lwc/guide/js-third-party-library.html). For developing Aura components, see [Using External JavaScript Libraries](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_libs_platform.htm).
- If you use third-party libraries that specify `"use strict"` explicitly, you can get errors under LWS. See [Third-Party Library Considerations for LWS](https://developer.salesforce.com/docs/platform/lightning-components-security/lws/lws-js.md#third-party-library-sets-strict-mode).

For more information about JavaScript strict mode, see the [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode).
