Home > Enterprise >  'use strict' is not working on some special cases. Can anyone clarify
'use strict' is not working on some special cases. Can anyone clarify

Time:02-04

I am trying to figure out why "use strict" is not working as per my expectation. Look at this working example.

"use strict"

x='Justin';
console.log(x)

As expected this produce error saying x is not defined. But check this next example

"use strict"

name='Justin';
console.log(name)

It outputs "Justin" without any error. Why is it happening what is so special about the variable "name"?

CodePudding user response:

When you run it in a browser, name refers to name property of the global object, which is Window. So it refers to Window.name.

  • Related