Javatpoint Logo
Javatpoint Logo

JavaScript Strict Mode

Being a scripting language, sometimes the JavaScript code displays the correct result even it has some errors. To overcome this problem we can use the JavaScript strict mode.

The JavaScript provides "use strict"; expression to enable the strict mode. If there is any silent error or mistake in the code, it throws an error.

Note - The "use strict"; expression can only be placed as the first statement in a script or in a function.

JavaScript use strict Example

Example 1

Let's see the example without using strict mode.


Here, we didn't provide the type of variable. Still we are getting an output.

Javascript Strict Mode

Let's see the same example by enabling the strict mode.


Now, it will throw an error as the type of x is not defined.

Javascript Strict Mode

Example 2

Let's see one more example to print sum of two numbers.


Here, an error occurs as we use duplicate elements.

Javascript Strict Mode
Next TopicJavaScript Promise

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA