Hi Fred, I think your article is very well written and it made me review my knowledge about JavaScript strict mode, so thank you for that! Now, it might just be a wording thing but I wanted to clarify that use strict will not prevent the assignment of variables in the global scope, it will only prevent the assignment of undeclared variables.
'use strict';//The assignment or reassignment of a declared variable will not throw an error.letglobalVariable='global value';globalVariable='another value';//This code will not throw an error.
'use strict';globalVariable='global value';//This will throw -> ReferenceError: assignment to undeclared variable globalVariable//Note that if you remove "use strict" it will not throw an error but create a global variable instead.
You're right that because use strict is preventing the accidental creation of global variables, it reduces the risk of name collision although it doesn't prevent the assignment of a declared variable, global or not. Again, thank you for the learning opportunity!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Fred, I think your article is very well written and it made me review my knowledge about JavaScript strict mode, so thank you for that! Now, it might just be a wording thing but I wanted to clarify that
use strict
will not prevent the assignment of variables in the global scope, it will only prevent the assignment of undeclared variables.Here's a reference to what I'm describing in the code block above : https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Erreurs/Undeclared_var?utm_source=mozilla&utm_medium=firefox-console-errors&utm_campaign=default
You're right that because
use strict
is preventing the accidental creation of global variables, it reduces the risk of name collision although it doesn't prevent the assignment of a declared variable, global or not. Again, thank you for the learning opportunity!