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?
()after function, it will call it immediately and assign its return value (in your case, undefined). Remove()and if you want to call it immediately, make a call on next line like:x();var x =is actually an IIFE stackoverflow.com/questions/8228281/…undefinedas it has no return