I'm trying to understand how can namespace be implemented in JavaScript. I'm checking out How do I declare a namespace in JavaScript?.
One of the answers mentioned the following TypeScript code.
namespace Stack {
export const hello = () => console.log('hi')
}
Stack.hello()
is compiled to the following JavaScript
var Stack;
(function (Stack) {
Stack.hello = () => console.log('hi');
})(Stack || (Stack = {}));
However, I find it hard to understand the above syntax, could someone explain how does it work? For example, how does the following work?
(function(Stack) {...})(...)
(Stack || (Stack = {}))