Hey, Phenomenal peoplešš»
Hello everyone, my name is Aryan Sharma, and I hope you're all doing well. I'm thrilled to begin this JavaScript course for absolute beginners with my third blog post.
You can find my blogs hereāļø
So, Let's dive!!
āuse strictā
JavaScript has developed without any compatibility problems for a very long period. The language now has additional capabilities while maintaining its previous functionality.
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.
"use strict";
Your JavaScript code here
Ensure that āuse strictā is at the top.
š«Please make sure that "use strict"
is at the top of your scripts, otherwise strict mode might not be enabled.
Strict mode isnāt enabled here:
alert("Code");
// "use strict" below is ignored
"use strict";
// strict mode is not enabled
Also, Keep in your mind, Thereās no way to cancel use strict
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
, orconst
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 toundefined
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.A strict mode is a useful tool for catching and preventing common programming mistakes. It encourages cleaner and more reliable JavaScript code by eliminating certain language features that are prone to errors or considered bad practices.
meme from supermeme or tenor
I Hope you loved the blogā£ļø
See u in the next blog...Stay tunedš¶