Strange behaviour with use strict

As expected I got an error with this:

'use strict';

userName = 'Max';

console.log(userName);

but not with this:

'use strict';

name= 'Max';

console.log(name);

As I am using strict mode. I expected to get an error with both code snippets, but turns out that i didn’t with the later. So, I am thinking maybe name is a reserved keyword of JavaScript; however, I didn’t find it listed among other.

Can someone explain why I didn’t get an error, please?

1 Like

do you maybe have a name variable defined somewhere in the code before that snippet? I get the ReferenceError: name is not defined

Nope, just the two snippets.

and when you run the code what do you see?

I saw this error stemming from line 3:

Uncaught ReferenceError: UserName is not defined
    at app.js:3

This was expected, but for the name variable i got the value, Max in the console.

https://www.w3schools.com/js/js_reserved.asp

ok, I was using nodejs, instead in a web page I see the same behaviour

it seems that in node there is not an already used name

in a webpage, name has a default value of empty string

1 Like

Thanks to both of you @ilenia @thetradecoder

1 Like

I didn’t know this before… many people use name as variable name… Thanks for clearing me