What is Strict Mode and how to enable it in JavaScript ? Last Updated : 08 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The strict mode of JavaScript, introduced in ECMAScript 5, is a mechanism to opt into a restricted version of JavaScript." Strict mode modifies the regular JavaScript semantics in the following ways: Some JavaScript silent errors are eliminated by converting them to throw errors. How to enable strict mode in JavaScript: Use "use strict" in front of the code where strict mode is necessary to enable strict mode. The strict mode can be enabled by simply stating it at the top of your script or in the required function. When a JavaScript engine encounters this directive, it begins to parse the code in a specific mode where error catching becomes easier. Advantages of using strict mode: The strict mode eliminates silent errors by changing them into thrown errors. so, it makes debugging easierWhen the delete operator is used where it is invalid strict mode throws errors.When the variables are used without being declared or we call them "accidental globals", strict mode throws an error.It doesn't allow duplicate property names or parameter values..When we do not use strict mode and our "this" operator points reference to null or undefined values it doesn't give an error but enabling the strict mode raises an error.Code written in strict mode can sometimes be made to execute quicker than code written in a non-strict manner. The strict mode doesn't allow the following instructions: We cannot directly use variables without declaring the variable.Parameters/arguments duplicates are not allowed.Deletion function not allowed.The words 'eval' and 'arguments' cannot be used as a variable.The 'with' statement is not allowed.Deleting a property that is undeletable.Writing to a read-only property. Examples: Demonstration without using the strict mode: In the below example we are assigning a variable without declaring it and then printing it. JavaScript a = 1; console.log(a); Output: Demonstration with using the strict mode: In the below example we are assigning a variable without declaring it and then printing it. we enable strict mode at the top of the code. The error message is displayed as we use strict mode. JavaScript "use strict"; a = 1; console.log(a); Output: Demonstration an example with or without using the strict mode: In the below example one part of the javascript code is running under strict mode and the other is running in non-strict mode. JavaScript // This will not cause an error a = 10; . console.log(a); withUsingStrict(); function withUsingStrict() { "use strict"; b = 20; // This will cause an error console.log(b); } Output: Comment More infoAdvertise with us Next Article How to Enable JavaScript on a MacOS? I isitapol2002 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads What is JavaScript Strict mode and how can we enable it ? JavaScript is a forgiving language as it ignores developers' or programmers' silly mistakes or errors in code like termination of the statement, variable declaration, the wrong data type of variable, hoisting issues, and many more. Sometimes these errors give unusual results which difficult for prog 4 min read How to Enable JavaScript on a MacOS? JavaScript is a programming language used to create dynamic content on web pages, such as animations or real-time updates, without needing to refresh the page. Enabling JavaScript in your browser is essential for a smooth online experience, like automatic updates on Facebook or Twitter timelines. In 2 min read How to Disable Input in JavaScript ? Disabling input fields in JavaScript is a common task when you want to restrict users from interacting with specific form elements. This can be useful in various scenarios, such as preventing modifications to fields that are conditionally locked or ensuring certain inputs are controlled programmatic 2 min read How to enable JavaScript in my browser ? We will explore the process of enabling JavaScript in web browsers to ensure seamless functionality of applications and websites. JavaScript serves as a fundamental component of modern web development, facilitating dynamic interactions and enhanced user experiences. However, encountering issues wher 2 min read JavaScript Strict Mode Strict Mode in JavaScript is a feature that helps catch common coding mistakes and implement a stricter set of rules to improve code quality. It eliminates silent errors, prevents the use of unsafe actions, and improves performance optimization by JavaScript engines.Use strict directiveThe "use stri 6 min read How to Disable and Enable JavaScript in Google Chrome? You may be wondering how a website looks with or without JavaScript. On Chrome, JavaScript is enabled by default, but you can disable it fairly quickly to see the impact on a site's functionality and appearance. Why Should I Enable or Disable JavaScript?Modern websites rely heavily on JavaScript to 4 min read Like