JS Coding Questions Logo
JS Coding Questions
#69💼 Interview💻 Code

How do you declare strict mode

Advertisement

728x90

The strict mode is declared by adding "use strict"; to the beginning of a script or a function.

If declared at the beginning of a script, it has global scope.

javascript
1"use strict";
2
3x = 3.14; // This will cause an error because x is not declared

and if you declare inside a function, it has local scope

javascript
1x = 3.14; // This will not cause an error.
2
3myFunction();
4
5function myFunction() {
6  "use strict";
7
8y = 3.14; // This will cause an error
9}

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 70

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
69of476