Hello everyone, my name is Aryan Sharma, and I hope you're all doing well.
This situation continued up until the release of ECMAScript 5 (ES5) in 2009. It changed some of the previous characteristics and added new ones to the language.
Most of these improvements are disabled by default to preserve the old code functioning. The specific directive "use strict" must be used to expressly enable them.
When "use strict" or 'use strict' is located at the top of a script, the whole script works the “modern” way.
🚫Please make sure that "use strict" is at the top of your scripts, otherwise strict mode might not be enabled.
There is no such directive like "no use strict" so to undo the effect of use strict
Once we enter strict mode, there’s no going back.
Now, you might be thinking why add use script ? or what are the benefits of adding use script in our JS code?🤔
Why use "use state"? One could recommend starting scripts with "use strict"… But you know why it is important to do so....?
Strict mode variables: In strict mode, variables must be declared before they are used. This prevents the accidental creation of global variables by omitting the var, let, or const keyword.
Eliminating silent errors: In strict mode, certain coding practices that can lead to silent errors are treated as explicit errors. For example, assigning values to read-only properties, deleting variables, or duplicating parameters.
Strict mode for functions: When "use strict" is applied to a function, that function and its nested functions operate in strict mode. If you're using modules, each module is implicitly in strict mode.
Changes to the "this" value: In strict mode, the value this inside a function is not automatically coerced to the global object (e.g., window in browsers) or to undefined in strict mode functions that are not methods. Instead, it remains the value it was set to when the function was called.
Octal literals and escape sequences: Octal literals (e.g., 0123) and certain escape sequences (e.g., \012) are not allowed in strict mode, as they were a source of confusion and potential errors.
I Hope you loved the article❣️
Don't forget to follow me