I declared two functions using function expression innerone and innertwo. I first declared innerone and after that innertwo. Inside innerone I am calling innertwo function. But my concern is that I am declaring innertwo after innerone using function expression which means innertwo is not hoisted. So why these functions work in this order? Is it mandatory to change their order?
Here is code
var one = function () {
var innerone = function () {
innertwo();
},
innertwo = function () {
console.log('innertwo');
};
return {
innerone: innerone
};
};
var o = new one();
o.innerone();
It’s working because innerone is called only when you call it. And by the time it’s called innertwo is defined.