Friday, March 2, 2018

Use Strict in your code

Every programmer must use "use strict" on top of their code. It will give you a best practice when you writing java script code.

Why Strict mode ?

  • Your java script code will be secure always. 
  • It will save you from bad syntax.
  • Prevents your code from some bad exceptions.

Some example with strict

Example 1:

"use strict";
x = 3.12121;

// Proper assign not happened here

The above will through an error like Uncaught Reference Error: x is not defined.

Example 2:

<script>
"use strict";
function x(x1, x1) {};
</script>

//p1 duplicates here

The above will through an error like Uncaught Syntax Error: Duplicate parameter name not allowed in this context


Like this we will face different types of error at different scenario. So better always use 'use strict'.







No comments:

Post a Comment