JavaScript:'use strict' for debugging

JavaScript

‘use strict’ is a JavaScript expression usually written on the beginning of code and is very helpful for debugging purpose. Let’s look at how using or not using use strict affect our code.

a = 2;
console.log(a);//2

The program runs without any error, but what if we put 'use strcict' in our code now.

'use strict'
a=2;
console.log(a);// "ReferenceError: a is not defined.."

Since, we have not declared a neither with var,let nor const, it threw an error.

It also throws error when variables are wrong spelled.

'use strict'
let number = 17;
numbre = 70;
if (number > 50){
  console.log(number);
}
//Output:"ReferenceError: numbre is not defined at...

'use strict' also restricts from using any reserved keywords like let,package,public,etc as variable names.