JavaScript Strict Mode: What it Does and Doesn’t AllowJavaScript Strict Mode: What it Does and Doesn’t Allow

Telegram Join Our Telegram Channel

In this tutorial, you will learn about the strict mode in JavaSript, the process of activating strict mode for a program or an individual function in JavaScript, and some typical actions that are forbidden by strict mode in JavaScript.

Activating JavaScript Strict mode

For activating Strict mode, you can add ‘use strict’; or “use strict”; at the beginning of the script.

Syntax:

‘use strict’;// or"use strict";

This statement should be the first statement in the script excluding comments as JavaScript just ignore them.

If there is any other statement before ‘use strict’; or “use strict”; then string mode will not activate.

Adding ‘use strict’; or “use strict”; at the beginning of the script has a global scope which makes all the code in that script executed in string mode.

Example:

"use strict";name = "John";console.log(name);

Output:

name = "John";

ReferenceError: name is not defined

Without Strict Mode:

name = "John";console.log(name);

Output:

John
Telegram Join Our Telegram Channel

One Response

Leave a Reply

Your email address will not be published. Required fields are marked *

Telegram Join Our Telegram Channel

Most Viewed

Monthly Best Selling Templates

Check the latest products added to the marketplace. Fresh designs with the finest HTML5 CSS3 coding.