‘use strict’ is literal expression which was introduced in ECMAScript 2015.
Basically, when you use ‘use strict’ it tells the Browser to execute code into ‘Strict mode’.
When you mention ‘use strict’ it won’t allow you to use undeclared variable into code.. it will throw an error and you can see the same into Developer console.
Strict mode is declared by adding “use strict”; to the beginning of a script or a function.
Note: The “use strict” is only recognized at the beginning of a script or a function.
Below are the operations which are not allowed in Strict mode.
- You can not use Variable without declaring it.
- You can not use Object without declaring it.
- Deleting Object/Function/variable is not allowed in Strict mode.
- Duplicate parameter names are not allowed.
- Writing of read only properties are not allowed.
- Keywords which are reserved for future of Javascript is not allowed to use, it will throw error.
- ‘eval’ can not be used as variable/object name
How to use strict mode.
Write
"use strict";
at the beginning of Javascript file or function.