I'm new to javascript and I have a trouble to understand the following javascript code. So is it possible for you guys to shed me the light on what is the purpose of having multiple functions nested inside the return. What is it for, why we need it and when we should use it.
Many thanks in advance
function create() {
var counter = 0;
return {
increment: function() {
counter++;
},
print: function() {
console.log(counter);
}
}
}
var c = create();
c.increment();
c.print();