Strange problem in console.log (name)

When I put console.logfor any variable in the browser console that is not declared, it will return Uncaught ReferenceError: the variable is undefined . But when I put console.log(name)in the browser console, it returns empty and undefined. See image below. any ideas why this is happening.

enter image description here

I tested it in Chrome and Firefox developer tools.

Note. I use clear () to clear the console

+4
source share
3 answers

name - , window. , , , ("") .

console.log(name);
console.log(window.name);
Hide result
+8

, , , , window.name .

, , :

window.name = 'stackoverflow';

console.log(), , "stackoverflow". , , ...

window.name, :

https://developer.mozilla.org/en-US/docs/Web/API/Window/name

+2

, , console.log(name):

  • name ( ).
  • , , window , , ​​ window.
  • , window.name name, .
  • , window / .
  • window.name "" ( ), .

, console.log(name100):

  • Same as before (name100 instead of name).

  • Same as before (name100 instead of name).

  • You have not declared the name 100 and are not its own property of the window object, so it just returns name100 is not defined.

If you want to check the properties that are sent using the window object, you can check this link:

+2
source

Source: https://habr.com/ru/post/1674969/


All Articles