Strict Mode
When doing coding exercises in plain vanilla js, I should use strict mode to help me write cleaner code.
- impossible to accidentally declare global variables with typos
- makes silent errors throw errors
Use at top declaration:
"use strict"
Use for function
function strict() { 'use strict'; function nested() { return 'And so am I!'; } return "Hi! I'm a strict mode function! " + nested();}function notStrict() { return "I'm not strict."; }
Use for module
function strict() { // because this is a module, I'm strict by default}export default strict;
Source -> Strict Mode on MDN docs