Javascript Strict Mode
Strict mode is declared by adding "use strict"; to the beginning of a script or a function. Strict mode makes it easier to write "secure" JavaScript. Strict mode changes previously accepted "bad syntax" into real errors.

The strict mode in JavaScript does not allow following things:

1. Use of undefined variables
2. Use of reserved keywords as variable or function name
3. Duplicate properties of an object
4. Duplicate parameters of function
5. Assign values to read-only properties
6. Modifying arguments object
7. Octal numeric literals
8. with statement
9. eval function to create a variable
undefined variables :
<html>
<head>
<title>Javascript undefined variables</title>
</head>
<body>
 
<script type="text/javascript">
 
"use strict";
 x = 1;
 
</script>
 
</body>
</html>
Javascript Reserved keywords :
<html>
<head>
<title>Javascript Reserved keywords</title>
</head>
<body>
 
<p id="Mesg"></p>
 
<script type="text/javascript">
 
"use strict";
try
{
var for = 1; // error
var if = 1; // error
}
catch(ex)
{
document.getElementById("Mesg").innerHTML = ex;
}
 
</script>
 
</body>
</html>
Javascript Duplicate Properties :
<html>
<head>
<title>Javascript Duplicate Properties</title>
</head>
<body>
 
<p id="mesg"></p>
 
<script type="text/javascript">
"use strict";
try
{
var myObj = { myProp: 100, myProp :"test strict mode" }; // error
}
catch(ex)
{
document.getElementById("mesg").innerHTML = ex;
}
 
</script>
 
</body>
</html>
Javascript Duplicate parameters :
<html>
<head>
<title>Javascript Duplicate Parameters</title>
</head>
<body>
 
<p id="mesg"></p>
 
<script type="text/javascript">
"use strict";
try
{
function Sum(val, val){ return val + val }; // error
}
catch(ex)
{
document.getElementById("mesg").innerHTML = ex;
}
</script>
 
</body>
</html>
Assign values to read-only properties :
<html>
<head>
<title>Javascript Assign Values</title>
</head>
<body>
 
<p id="mesg"></p>
 
<script type="text/javascript">
"use strict";
try
{
var ary = [1 ,3 ,5 ,12, 15];
ary.length = 25; // error
}
catch(ex)
{
document.getElementById("mesg").innerHTML = ex;
}
</script>
 
</body>
</html>
Javascript Modify arguments object :
<html>
<head>
<title>Javascript Modify arguments object</title>
</head>
<body>
 
<p id="mesg"></p>
 
<script type="text/javascript">
"use strict";
try
{
function Sum(val1, val2){
arguments = 100; // error
}
}
catch(ex)
{
document.getElementById("mesg").innerHTML = ex;
}
</script>
 
</body>
</html>
Javascript Octal literals :
<html>
<head>
<title>Javascript Octal literals</title>
</head>
<body>
 
<p id="mesg"></p>
 
<script type="text/javascript">
"use strict";
try
{
var oct = 021; // error
}
catch(ex)
{
document.getElementById("mesg").innerHTML = ex;
}
</script>
 
</body>
</html>
Javascript with statement :
<html>
<head>
<title>Javascript with statement</title>
</head>
<body>
 
<p id="mesg"></p>
 
<script type="text/javascript">
   "use strict";
try
{
with (Math){
x = abs(162.198, 4); // error
};
}
catch(ex)
{
document.getElementById("mesg").innerHTML = ex;
}
 
</script>
 
</body>
</html>
Eval function to create a variable :
<html>
<head>
<title>Javascript Eval function to create a variable</title>
</head>
<body>
 
<p id="mesg"></p>
 
<script type="text/javascript">
       "use strict";
try
{
eval("var x = 5");// error
}
catch(ex)
{
document.getElementById("mesg").innerHTML = ex;
}
</script>
 
</body>
</html>