<html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- C# anonymous function--> <title></title> <script type="text/javascript"> var f1 = function (x, y) { //【1】 Define an anonymous function and point it to it with the variable f1 (f1 is equivalent to a delegate, and f1 can be used as a function) return x + y; } //Call this anonymous function alert(f1(5, 6)); //Output 11 //【2】 It can also declare that the anonymous function immediately uses alert(function (a, b) { return a + b } (10, 2)); //Directly declare an anonymous function function (a, b) { return a + b }, and then directly use function (a, b) { return a + b } (10, 2). Even the variable f1 pointing to the anonymous function function (a, b) { return a + b } is not needed. Here output 12 //【3】Anonymous function var f2 without parameters var f2 = function () { alert("Hello") }; f2(); //Output "Hello" var f3 = function () { return 5 }; alert( f3() + 5);//Output 10 </script> </head> <body> </body> </html>