I wonder if there is really nessesary to include the "use strict"
when I am done programming and release my JavaScript document to anyone to see. I like to use it because to check that I have coded in a good way.
So, should I include or just remove use "use strict"
when I release my JavaScript file for the public?
The reason why I ask is to save space in my JavaScript file.
If you have such an unrestrictedly typed code, that is used variables without declaring. One variable declared within some function/scope and used from somewhere else(it will be undeclared there) and you can't rewrite/change them, then you should not go for "use strict;" mode because it will break the code.
Strict mode eliminates some JavaScript silent errors by changing them to throw errors. Strict mode fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that's not strict mode.
The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables. The numbers in the table specify the first browser version that fully supports the directive. You can use strict mode in all your programs.
To invoke strict mode for an entire script, put the exact statement "use strict"; (or 'use strict'; ) before any other statements.
I found two opinions about using strict mode
in production:
There is no reason to ship “use strict” in your production code. There is no performance gain (verified with V8 team and Brendan a while ago) and I don’t need my users’ VMs doing the extra checks as well. Keep it development only, strip it out during build. This way you also avoid the concatenation issue you reference.
And:
There may not be a performance gain, but there’s also not a performance loss. In production, even more than in development, is where you want to be sure you’re noticing errors. Minimizing the changes between the development and production versions of the code is key to being able to debug issues quickly and efficiently. Yes it helps during development, but there’s no reason to pull it out of production code.
The source is in the comments at the bottom
And of course those 12b
weight of "use strict"
won't change a thing.
The line "use strict";
makes up 13 bytes of your file. I'd suggest that this is unlikely to even approach 1% of your file size.
Use one of the many minifiers out there to reduce your file size, along with gzip comression on the server-side, if you're concerned about bandwidth. Manually removing 13 bytes is a false economy.
Exactly which minifier may depend on your code, but here are some suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With