I was going through some practice sessions and I came to learn that in JS, functions are also object. So I tried the following.
function say() {
console.log("hi")
}
var obj1 = say;
obj1.hello = "hello";
console.log(say.hello); // hello
then I tried doing the same with an object, but got undefined
and I expected to get winter
.
var obj2 = { weather: "summer", time: "noon" };
var name = obj2;
name.favoriteWeather = "winter";
console.log(name.favoriteWeather); //undefined
Why JS behaves the way it does? how can I get winter
as result from name.favoriteWeather