DEV Community

SYED MAZHAR ALI RAZA
SYED MAZHAR ALI RAZA

Posted on

The Strict mode in JavaScript

JavaScript's strict mode, introduced in ECMAScript 5, optimizes code for JS engine, eliminates bad-syntax code, and helps in writing secure JavaScript. Let's take a slightly deeper dive into this concept.

"Use strict" mode in JS applies certain restrictions in the entire script or in a particular function it is invoked in. Just add "use strict"; to the beginning of a script or a function.

Q. What changes does use strict make? The list is pretty exhaustive. But here are some important changes you'll notice. If you're in strict mode:

  • Using a variable/object, without declaring it, will throw an error.

  • Using duplicate parameters in any function or duplicate property names in any object will throw an error.

  • Any assignment that silently fails (does not throw any error/no feedback to the user) in normal code (i.e assignment to a non-writable global or property, assignment to a getter-only property, assignment to a new property on a non-extensible object) will throw an error.

  • Deleting a function or an undeletable property will throw an error.

  • Using a number that begins with 0 will throw an error.

  • Setting a property to a primitive value, will throw an error.

  • There are a number of situations that could unintentionally cause this to be bound to the global object. In strict mode, instead of bounding this to global object, this gets bound to undefined.

  • ECMAScript 5 added a list of reserved words that will be used in the future. If you use them as variables or arguments, the strict mode will throw an error.

  • Using arguments.callee, arguments.caller, with keyword,eval() function, is forbidden.

  • Et cetera, et cetera.

Refer to this MDN doc on the same for further information and clarity.

Happy coding :)

10DaysofJSfundamentals (DAY 6)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more