Anonymous functions in JavaScript
Anonymous function:
is a function without a name.
Anonymous functions cannot be defined or called individually.
Anonymous functions are generally used as data to assign values to other variables. You can assign values to ordinary variables, array elements, and object properties.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var a=88 ;//将数值赋值给变量a,此时变量a就是“数值型”变量 var a="asd"; //将字符串赋值给a,此时变量a就是“字符型”变量 var a=true; //将布尔值赋值给变量a,此时变量a就是“布尔型”变量 var a=[10,20];//将数组赋值给变量a,此时变量a就是“数组型”变量 var a=function(name,age){//将函数值赋值给变量a,此时变量a就是“函数型”变量 window.alert("我叫"+name+"今年"+age+"岁"); } //调用函数 a("小明",20); var b=a;//将变量a的地址,拷贝一份传给变量b b("小白",22); </script> </head> <body> </body> </html>