---restore content starts---
function functions:
Functions are actually objects, each of which is an instance of a function type, and all have properties and methods like other reference types, and the function name is actually a pointer to a function that is not bound to a function;
Three ways to define a function:
1. Function declaration
function sum (num1,num2) { return num1 + num2; }
2. Function expression, also called function literal
var function (num1,num2) { return NUM1 + num2}
3. Function construction method, parameters must be quoted
var sum3=New Function (' N1 ', ' N2 ', ' return n1+n2 '); Console.log (sum3 (2,3)); // 5
Three differences: the parser reads the function declaration first and makes it accessible before executing any code, and the function expression must wait until the line of code where the parser is executing is actually interpreted, and there is a semicolon at the end of the function expression, just like declaring other variables. The third method is generally not recommended, because this syntax can result in parsing two of times of code (parsing the regular ECMAScript code for the first time, and the second parsing the string passed into the constructor), thus affecting performance.
<script>alert (SUM (2,3)) functionsum (sum1,sum2) {returnSum1 +sum2; }</script>result:5<script>alert (SUM (2,3)) varsum =function(sum1,sum2) {returnSum1 +sum2; }<script>Result: Error---sum is not afunction<script>varsum =function(sum1,sum2) {returnSum1 +sum2; } alert (SUM (2,3))</script>
Retult:5
Note: Because the function name is just a pointer to a function, a function may have more than one name
---restore content ends---
function functions:
Functions are actually objects, each of which is an instance of a function type, and all have properties and methods like other reference types, and the function name is actually a pointer to a function that is not bound to a function;
Three ways to define a function:
1. Function declaration
function sum (num1,num2) { return num1 + num2; }
2. Function expression, also called function literal
var function (num1,num2) { return NUM1 + num2}
3. Function construction method, parameters must be quoted
var sum3=New Function (' N1 ', ' N2 ', ' return n1+n2 '); Console.log (sum3 (2,3)); // 5
Three differences: the parser reads the function declaration first and makes it accessible before executing any code, and the function expression must wait until the line of code where the parser is executing is actually interpreted, and there is a semicolon at the end of the function expression, just like declaring other variables. The third method is generally not recommended, because this syntax can result in parsing two of times of code (parsing the regular ECMAScript code for the first time, and the second parsing the string passed into the constructor), thus affecting performance.
<script>alert (SUM (2,3)) functionsum (sum1,sum2) {returnSum1 +sum2; }</script>result:5<script>alert (SUM (2,3)) varsum =function(sum1,sum2) {returnSum1 +sum2; }<script>Result: Error---sum is not afunction<script>varsum =function(sum1,sum2) {returnSum1 +sum2; } alert (SUM (2,3))</script>
Retult:5
Note: Because the function name is just a pointer to a function, a function may have more than one name
JavaScript Knowledge points Summary----function definitions