Node.js JavaScript syntax [duplicate]

This is a self invoking anonymous function. This pattern is useful when you want to hide variables from the global namespace.

(function(){
    var foo = "foo";
})();

console.log(window.foo); // undefined

Also see What do parentheses surrounding a JavaScript object/function/class declaration mean?

What advantages does using (function(window, document, undefined) { … })(window, document) confer?

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)