Home >Web Front-end >JS Tutorial >JS anonymous function example analysis
The examples in this article describe JS anonymous functions. Share it with everyone for your reference, the details are as follows:
/* 匿名函数*/ (function() { var foo = 10; var bar = 2; alert(foo * bar); })(); /* 匿名函数,带参数 */ (function(foo, bar) { alert(foo * bar); })(10, 2); /* 匿名函数返回值 */ var baz = (function(foo, bar) { return foo * bar; })(10, 2); // baz will equal 20. /* 匿名函数关闭 */ var baz; (function() { var foo = 10; var bar = 2; baz = function() { return foo * bar; }; })(); baz();