Format:
(function() {// Code }) ();
function expressions can be stored in variables, and variables can be used as a function to pass anonymous functions as parameters to other functions, the receiver function can be passed in by the function to complete some functions can be performed through anonymous functions of some one-time tasks
<!doctype html>// Test code URI function var test1= function(x, y) {return x*y; }; var test2=function(x, y) {return x+y;}; Alert (test1 (3,5)); Alert (test2 (2,6)); </script></body>
callback function saves global variables and improves performance<script type= "Text/javascript" >//function to test the encoding URI //var test1=function (x, y) {return x*y;}; //var test2=function (x, y) {return x+y;}; //Alert (test1 (3,5)); //alert (test2 (2,6)); //example of a callback function functionCalc (x, y) {returnX () +y (); } functiontest3 () {return3; } functiontest4 () {return5; } //Alert (Calc (test1,test2));Alert (Calc (function(){return10;},function(){return5;}));</script>
function returns 15
JavaScript anonymous functions and callback functions