Skip to content

Simple functional Style

PhoenixAndMachine edited this page Apr 7, 2014 · 1 revision

Simple functional Style

You can define an anonymous function and execute immediately by

(function(){
	var foo = 10;
	var bar = 2;
	console.log(foo * bar); // 20
})();

You also can define an anonymous function with arguments and execute immediately by

(function(foo, bar) {
	console.log(foo * bar); // 20
})(10,2);

You can define an anonymous function that returns a value by

var baz = (function(foo, bar) {
	return foo*bar; 
})(10,2);

console.log(baz); // 20

Clone this wiki locally