What is a function in JavaScript
When designing a complex program, it is necessary to divide the program into some relatively independent parts according to the functions to be completed, and write a "function" for each part. Thus, each part is fully independent, has a single task, and the program is clear, easy to understand, read, and maintain.
JavaScript functions can encapsulate modules that may be used multiple times in a program and can be called as a result of event-driven programs, thereby implementing a function to associate it with event-driven programs. This is What makes it different from other languages.
In JavaScript, a function is defined by the keyword function, and a function can have multiple parameters. The basic format is:
function 函数名 (参数1,参数2) { 函数体; return 返回值; }
When calling (using) a function, pass in the corresponding parameters and execute various statements in the function body such as if/else, switch/case, for, while, etc., to achieve various complexities. function.