'use strict';
One use case is as a temporary measure during development to uncover errors that would otherwise fail silently. Additionally, if browser support can be managed, it is possible to use this mode in production which, in some cases, will allow code to run faster.
Strict mode makes several changes to normal JavaScript:
- Strict mode will throw errors instead of allowing some errors to fail silently.
- Strict mode changes how the JavaScript engines perform optimizations, which can lead to the improved performance mentioned above.
- Strict mode rejects syntax that is likely to be used in future ECMAScript versions.
↓ Example ↓
// Setup the variable
const myVariable = {
name: "John"
};
// Freeze it preventing any changes
Object.freeze(myVariable);
// Try to redfine the variable, whch will fail silently
myVariable.name = "Change after .freeze()"
console.log(myVariable); // RESULT: "The Changed Name" because the Object was frozen
// Opt in to strict mode.
'use strict';
// Try to redfine the variable, whch will now throw an error instead of failing silently
myVariable.name = "Change after .freeze()"















