1'use strict';
2//Strict mode makes some bad practices return errors.
3//Some programmers use this to help them avoid bad habits.
1/*
2even though x is not defined with a keyword like var, let or const, the
3browser won't throw an error
4*/
5x = 1;
6
7function myFunc() {
8 "use strict";
9
10 /*
11 this will throw an error as y is being assigned a value without it
12 being declared AND "use strict" has been used for the function
13 */
14 y = 4;
15}
16
17/*
18Basically, "use strict" is a way for programmers to avoid bad habits by using
19invalid syntax which browsers accept but is still wrong
20*/
1// Whole-script strict mode syntax
2'use strict';
3var v = "Hi! I'm a strict mode script!";
4
1Strict mode makes several changes to normal JavaScript semantics:
2-Eliminates some JavaScript silent errors by changing them to throw errors.
3-Fixes mistakes that make it difficult for JavaScript engines to perform
4optimizations: strict mode code can sometimes be made to run faster than
5identical code that's not strict mode.
6-Prohibits some syntax likely to be defined in future versions of ECMAScript.