Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use JavaScript function

Shulou Source: shulou.com Published: 2022-06-02 08:24:52 09月20日 Update

Editor to share with you how to use the JavaScript function, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

JavaScript function

Function provides a rich and convenient ability for programmers. Usually when a complex program is designed, the program is divided into some relatively independent parts according to the function to be completed, and each part is written with a function. Thus, each part is fully independent, the task is single, the program is clear, easy to understand, easy to read and easy to maintain. The JavaScript function can encapsulate modules that may be used many times in the program. A program that can be called as an event-driven result. To implement a function to associate it with an event driver. This is different from other languages.

1. JavaScript function definition

Function function name (argument, argument)

{

Function body;.

Return expression

}

Description: when calling a function, the variable or literal quantity used can be passed as a variable. Function is defined by the keyword Function

Definition. Function name: defines the name of your own function. Parameter table, which is passed to the function for use or operation

Value, which can be a constant, a variable, or other expression. Call a by specifying a function name (argument)

A function. The value must be returned using Return. Function names are case-sensitive.

2. Formal parameters in the function:

In the definition of the function, we see that there is a parameter table after the function name, and these parameter variables may be one or more. So how can we determine the number of parameter variables? You can check the number of parameters through arguments. Length in JavaScript. Example:

Function function_Name (exp1,exp2,exp3,exp4)

Number = function _ Name. Arguments .length

If (Number > 1)

Document.wrile (exp2)

If (Number > 2)

[xss_clean] (exp3)

If (Number > 3)

[xss_clean] (exp4); these are all the contents of the article "how to use the JavaScript function". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Functions parameters programs variables articles parts number events content parameter tables programming expressions independence design drivers complexity less people tasks keys Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information MariaDB Xiaomi Apple