“use strict” in Javascript

Rollin_J
May 3, 2021

Safer feature set of javascript

image from unsplash

It makes function or program to work in a strict mode. It makes code faster, secure and throws any unwanted(silent) error when any unsafe event take place.

How to use:
a.strict mode for whole code, add “use script” at the very begning of the code.

b.strict mode for function, add “use script” at the very begning of the function

Why use “strict”:

  1. It restricts creation of global variable, object without declaring it.

first let’s create vaiable and object without use strict

no error

with “use strict”, and above assignment results in error

throws an error

2. Deleting function, variable and object is not allowed

3. Can not use same parameter name in function

4. Escape characters are not allowed in strict mode.

--

--