Is a variable called "name" always defined in Javascript?
Is a variable called "name" always defined in Javascript?
Not. However, browsers have a global name , which is the name of the current window. This is a byproduct of the fact that the global JavaScript object in browsers is a Window object. A little explanation:
In JavaScript, global variables are actually properties of what is called a global object. In browsers, a global object is a Window object for a page, and therefore it has all sorts of predefined properties (and therefore global) on it, associated with it as a Window object , including, but not limited to:
name- name of the current windowtitle- name of the current windowdocument- document in the current windowwindow- a reference to a global object (for example, a circular link)setTimeoutis a function used to schedule what happens later.
... and many others. It also gets all sorts of other things into it, such as a property for each DOM element with id (the name of the property is id , its value is a reference to the DOM element), on some browsers the same is true for DOM elements with the name property, etc. . He was very clogged.