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
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
b1mind
b1mindā€¢2y ago
Its implied for you when you use JS modules right?
ƅ Marlon G
ƅ Marlon GOPā€¢2y ago
šŸ˜®ā€šŸ’Ø 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?
b1mind
b1mindā€¢2y ago
ESM*
ECMAScript modules uses strict mode by default
ƅ Marlon G
ƅ Marlon GOPā€¢2y ago
But isn't that just for some parts of the script?
b1mind
b1mindā€¢2y ago
It depends how you are importing and using it https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
ƅ Marlon G
ƅ Marlon GOPā€¢2y ago
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.
ƅ Marlon G
ƅ Marlon GOPā€¢2y ago
And when I start making scripts to implement for web I'll annoy you again. šŸ˜ˆ
b1mind
b1mindā€¢2y ago
Just don't write the old way and you can impose strict on yourself and never really worry about it šŸ˜‚
ƅ Marlon G
ƅ Marlon GOPā€¢2y ago
I have no idea what the old way is. šŸ¤”
b1mind
b1mindā€¢2y ago
dont use this == that or var for example. Always use === or let/const You will following that it teaches you modern JS
ƅ Marlon G
ƅ Marlon GOPā€¢2y ago
Aha! That I know ... so "use strict" makes var into let, for example?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
b1mind
b1mindā€¢2y ago
It will make you declare it but not which type. So you can't do that = 69 without a var/let/const
ƅ Marlon G
ƅ Marlon GOPā€¢2y ago
Haha!!! 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
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
b1mind
b1mindā€¢2y ago
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.
ƅ Marlon G
ƅ Marlon GOPā€¢2y ago
Summary: I will only write let/const, === and leave "use strict" for later. šŸ˜…
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server