I am new in Javascript, but have deep background real OO languages like C#, Java, C++... In Javascript there is a concept called anonymous functions. Here is a sample code:
( function() {
for(var x = 0;x<5;x++) {
console.log(x);
}
})();
As I have understood the parantheses at the end make the function call itself. There is also another syntax which does the same:
var x = function() {
for(var x = 0;x<5;x++) {
console.log(x);
}
}();
But right now if I try to use x
, it does not execute the function again. So what is the goal if using the assignment in the second version? Can I use the function via x
again?