Tuesday, March 10, 2009

Anonymous functions

An interesting fact:
var sum = function(x,y,z) {
return (x+y+z);
}(1,2,3);
is an anonymous function. That means sub is now 6. If you call sum with any arguments it will bark at you. Where as this:
var sum = function(x,y,z) {
return (x+y+z);
};
is a named function. Sum is a function that accepts 3 arguments. If you call sub(2,3,5), it will return 10.

No comments: