JS Series: EP. (II) - May the "use strict" be with you.


This is the second article of the Javascript Starwars series So lets get started with "use strict".
What is "use strict"?
The "use strict" feature was introduced in ES5 in javascript. "use strict" is neither just an expression nor a statement it is a literal expression. which is written on top of our javascript file or a specific function.
Why "use strict"?
So every time a new feature is introduced in javaScript creators got to be very careful before releasing the feature to the language, as a single mistake could make it stuck in the language forever.
Something like this happened with the ES5 introduction. It added new features to the language and modified some of the existing ones.
Hence most of the new features introduced here were kept "off" by default and if the developer wants to use the new features can add "use strict" in the js file.
Syntax
"use strict";
... // code with new syntax here
Strict mode makes it easier to write "secure" JavaScript.
Example: Without "strict mode"
a = 5;
// declaration without variable type (no error)
function fun(param1, param1) {}
// both param variables have same name (no error)
Example: With "strict mode"
"use strict";
a = 5; // Ref error use var let or const
function fun(param1, param1) {} // Syntax error duplicate param names
"use strict" in modern ways
In modern times if we use Classes or some special JS module then we even do not have to write "use strict" explicitly in the file. That's why we do not worry much about it today.
Fun Fact: Browser consoles does not have "use strict" enabled by default. So you can expect some strange result sometimes in console.
So yeah, That was a quick intro about "use strict" More learnings ahead...
Stay Tuned for the next Episode. Thanks.
✍️ Medium — https://codecutters.medium.com/
☕️ Buymeacoffee — https://www.buymeacoffee.com/codecutters
🦄 Hash node — https://codecutters.hashnode.dev/
❤️ Youtube — https://www.youtube.com/@codecutters/
Ya ya, you going… I know, and haven’t followed me yet? no problemo.
Just kidding Please "Like share and Follow" until your hands are tired…
ha ha ha … May the javascript be with you :)
Subscribe to my newsletter
Read articles from Code Cutters directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Code Cutters
Code Cutters
Focused on making coding concepts strong. From Basics to the Latest trends. #frontend #webdevelopment #coding #interview #javascript #systemdesign 🚩 Advanced Frontend ✅ Clean code 🚀 Web Performace 🙊 No code / Low code 🧠 DSA & Problem Solving ⏳ Interview Prep.