'What is the global variable called 'name' in javascript? [duplicate]
Why is it that assigning a DOM element to the global variable "name" doesn't work ?
Solution 1:[1]
In the global space there is only one name property possible which is that of the Window object and you can only assign a text string as its value. The purpose of this global variable associated with the Window object is to set targets for hyperlinks and forms. However, you may create a property called 'name' with another object as long as it originates from where the object is created, as follows:
function season(name, starts, equinox) {
this.name = name;
this.starts = starts;
this.equinox=equinox;
};
function demoObj(favSeason,presDay) {
this.favSeason = favSeason;
this.presDay = presDay;
};
const seasonNow = new season('Spring','March','Vernal');
const o = new demoObj(seasonNow,'2-20-2022');
console.log("Favorite season: " + o.favSeason.name + " [as of " + o.presDay+ "]");
More info here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
