There are some quick notes of "use strict"
in javascript:
"use strict"
:
– Is a string
– Define in the top of .js
file or top of function
– If old browsers don’t support it, they will omit it
How to use?
- Prevent assigning value to undefined variable
=> Comment the first line, run the code again & see there is no error
- Prevent using let as a variable name
let
is a keyword that used for block scope from ES 6
- Don’t allow to delete variables, functions or arguments
- Safer to use eval() function
- eval() evaluates a javascript expression by providing a string i.e.
eval("var a = 2")
<=>var a = 2;
- KEEP variables which are defined in eval function are only in eval’s scope
- eval() evaluates a javascript expression by providing a string i.e.