Simplest possible code in hello.js
(function() {
console.log("Hello World!");
});
Running it with : $node hello.js
There is NO output. If I remove the enclosing function, works properly. But I do want to use the closure. Any ideas?
Node version 0.10.30. Ubuntu 12.04 x64
You,re not running your function.
You should add function call:
(function() {
console.log("Hello World!");
}).call();
or simply
(function() {
console.log("Hello World!");
})();
You need to call the function for it to work.
(function() {
console.log("Hello World!");
})();
Note the added parentheses that call the function after it's been defined.
You are just defining your function, without calling it. You should adapt your script as follows:
console.log("Hello World!");
OR add call your function:
(function() {
console.log("Hello World!");
}).call();
OR:
(function() {
console.log("Hello World!");
})();
A good resource online to try various scripts is this