Logo


useStrict in javascript


In this article,we are using a useStrict mode by putting strictmode on first line or with some function.


1'use strict';

In non strict variable,undeclared variable creates a global variable for example :


1function sloppyFunc() {
2      undeclaredVar1 = 123;
3}
4sloppyFunc();
5// Created global variable undeclaredVar1:
6assert.equal(undeclaredVar1, 123);

The functions shows an error when it is called

1function strictFunc() {
2'use strict';
3undeclaredVar2 = 123;
4}
5assert.throws(
6() => strictFunc(),
7{
8name: 'ReferenceError',
9message: 'undeclaredVar2 is not defined',
10});

About

Moiz is a software engineer from Arid University with a passion for writing tech tutorials and doing coding. I am continously produce JavaScript and other web development technology tutorials in concepts through easy-to-understand explanations written in plain English.I have expertise in next js ,react js ,javascript,html,bootstrap and node js.

Follow him on Twitter

Hassan is a software engineer from kohat university of science and technology with a passion for writing tech tutorials and doing javascript practices on daily basis.I have expertise in next js ,react js ,javascript,html,bootstrap and node js. Problem Solving and making concpets is my strong point.

Follow him on Twitter

Tags

Click to see all tutorials tagged with:

© Copyright 2023 Pak Annonymous | Back To Homepage | Privacy Policy
Share