I'm a newbie to js and recently I've learned that we can navigate to a new page in a browser tab by assigning a new value to the window.location object like: window.location = "https://www.stackoverflow.com". But I'm confused about this assign operation. In javascript, a variable changes it's type and value in an assign operation. For example, when running the following program segment, the type of a will be undefined then number and finally string:
var a;
a = 1;
a = "str";
But assigning a string object (i.e. the url) to window.location doesn't change it's type, window.location is still an instance of Location class, only with some of it's attributes changed (e.g. window.location.href, window.location.host etc.). This is just like overloading the "=" operator with the window.location.assign() function, but it seems that javascript doesn't offer an overload mechanism. I have no idea what do browsers (i.e. the javascript running environment) do to achieve this. I would be grateful if anyone can help me with this problem.
setterprobably: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…window.location, it doesn't become the string object but use the the url to change it's attributes instead, just aswindow.location.assign()is called.