There are named functions in JavaScript. You can use the function keyword to declare a named function. The syntax is "function function name (parameter list) {statement block to be executed;}"; the named function can be called before and after the named function declaration. When the function declaration is promoted, it will be automatically promoted to the top. .
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
JavaScript has named functions
function 函数名(参数列表){//function声明函数的关键字 要执行的语句块; }
function: Keywords that define functions (must be lowercase)
Function name: A custom name (the function must be called in the same case as the function name)
Function body: A certain piece of code to be encapsulated, which can complete a specific function
Features: Function declaration promotion, automatically promoted to the top
Function declaration can be called anytime and anywhere. Named functions can be called before and after, anonymous functions can only appear after being called after the function.
The JavaScript code taking unit is a function. The function can contain a piece of executable code, and can also accept parameters passed in by the caller. There are mainly the following ways to define functions in JavaScript:
The first way: named function
<script> function 函数名(参数列表){//function声明函数的关键字 要执行的语句块; } function myAge(age) { document.write('我的年龄是' + age)//我的年龄是19 } myAge(19)//函数不调用,不执行 </script>
The second way: anonymous function
<script> function (参数列表) {//同引用函数调用这个函数 要执行的语句块 } //匿名函数 var a=function(age) { document.write('我的年龄是' + age)//我的年龄是19 } a(19) </script>
Named functions are different from anonymous functions. Named functions can be called before and after, while anonymous functions can only appear after being called after the function.
[Related recommendations: javascript video tutorial,webfrontend】
The above is the detailed content of Does JavaScript have named functions?. For more information, please follow other related articles on the PHP Chinese website!