How to declare
- Ensure that “use strict” is at the top
- There’s no way to cancel
Some examples while implementing:
In the above example, declared inside a function, it has a local scope (only the code inside the function is in strict mode).
In the above example, we can see that using a variable, without declaring it, is not allowed.
use strict automatically. So we don’t need to add the
"use strict" directive if we use them.
So, for now
"use strict"; is a welcome guest at the top of your scripts. Later, when your code is all in classes and modules, you may omit it.
this keyword in functions behaves differently in strict mode.
this keyword refers to the object that called the function. If the object is not specified, functions in strict mode will return
undefined and functions in normal mode will return the global object (window).