1.

Remove whitespace from both sides of a string in JavaScript

Answer»

The “USE strict” is a literal expression introduced in ECMAScript version 5. It indicates that the code should be executed in "strict mode", which in turn considered a good practice.

The key use of this mode is if you won’t declare a variable and use it, then an error would be visible. Let us see what we discussed using the following example:

<script> "use strict"; // a is not defined a = 10;   </script>

Since, variable “a” is not defined above, the following error would be visible if you will Press F12 for debugging:

a is not defined

The following is not allowed in strict mode with “use strict”:

Case1: It is not allowed to delete a variable in strict mode

"use strict"; // error var a = 10; delete a;  

Above generates the following error in strict mode, when you will enable debugging with F12 on web browser:

Error: DELETION of an UNQUALIFIED identifier in strict mode

Case 2: Using Octal numeric LITERALS are not allowed

<script> "use strict"; // error var a = 012; </script>

Above generates the following error in strict mode, when you will enable debugging with F12 on web browser:

Error: Octal literals are not allowed in strict mode


Discussion

No Comment Found