Here we will need a node js server to run this program which is saved as js extension
In the following program, we created a closure of the Stack function and passed/called the messages like push, pop & print.
var variables within Stack function are local to stack function and hence we can say this is an idiom for achieving the encapsulation principal of a class.
obj is the object here, so what if we say
obj.sp = 20;
Don’t worry, this will create a new variable inside obj table/object which will not affect the functionality of the closure that we are working onto i.e. Stack for now.