When use "use strict"
Hello...
First time coding in JS.
Cam across this: https://javascript.info/strict-mode
Does this mean that I always have to put
"use strict"
at the top, or only if there is old JS to be implemented along side new?
I'm writing new, fresh, lovelly JS-files, do I need it then?19 Replies
Unknown Userā¢2y ago
Message Not Public
Sign In & Join Server To View
Its implied for you when you use JS modules right?
š®āšØ
Not a fan of the, choose if you want, options ...
So, as a first timer in JS maybe I should use it since it says
changes making it easier to write "secure" JavaScript
?ESM*
ECMAScript modules uses strict mode by default
But isn't that just for some parts of the script?
It depends how you are importing and using it
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
I'm on level 0 of JS, and this was one intro to it: https://javascript.info/strict-mode (Am also trying codecademy's intro to JS)
Bam! In the JS fundamentals ... So that makes me feel like I need to understand it now before I learn more.
I think the answer to this is I'm gonna ignore it for now.
And when I start making scripts to implement for web I'll annoy you again. š
Just don't write the old way and you can impose strict on yourself and never really worry about it
š
I have no idea what the old way is. š¤
dont use
this == that
or var
for example. Always use ===
or let/const
You will following that it teaches you modern JSAha! That I know ... so "use strict" makes var into let, for example?
Unknown Userā¢2y ago
Message Not Public
Sign In & Join Server To View
It will make you declare it but not which type. So you can't do
that = 69
without a var/let/constHaha!!! Yes, I also think this is nonsense for me right now. I just exploded my head over how totally illogical functions are written out. I'll battle with them for now.
š¤£
Unknown Userā¢2y ago
Message Not Public
Sign In & Join Server To View
Yea my point was not to derail you to something else either, just pointing out later lots of the times you will be dealing with ESM so it will be auto strict mode, its good to know about but you wont really be writing that line in projects.
Summary: I will only write
let/const
, ===
and leave "use strict"
for later.
š
Unknown Userā¢2y ago
Message Not Public
Sign In & Join Server To View