Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of JavaScript function Syntax, function call and function return

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the JavaScript function syntax, function calls and function return instance analysis of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that everyone after reading this JavaScript function syntax, function calls and function return instance analysis article will have something to gain, let's take a look.

JavaScript functions are blocks of code designed to perform specific tasks.

The JavaScript function is executed when some code calls it.

Example

Function myFunction (p1, p2) {

Return p1 * p2; / / this function returns the product of p1 and p2.

}

JavaScript function syntax

The JavaScript function is defined by the function keyword, followed by the function name and parentheses ().

Function names can contain letters, numbers, underscores, and dollar signs (rules are the same as variable names).

Parentheses can include parameters separated by commas:

(parameter 1, parameter 2, … )

The code executed by the function is placed in curly braces: {}

Function name (parameter 1, parameter 2, parameter 3) {

Code to be executed

}

The function parameter (Function parameters) is the name listed in the function definition.

The function parameter (Function arguments) is the real value received by the function when it is called.

In a function, parameters are local variables.

In other programming languages, a function approximation program (Procedure) or a subroutine (Subroutine).

Function call

The code in the function will be executed when other code calls the function:

When the event occurs (when the user clicks the button)

When the JavaScript code calls

Automatic (self-calling)

You will learn more about function calls in this tutorial.

Function return

When JavaScript reaches the return statement, the function stops execution.

If the function is called by a statement, JavaScript will "return" to execute the code after the calling statement.

Function usually calculates the return value. This return value is returned to the caller:

Example

Calculates the product of two numbers and returns the result:

Var x = myFunction (7,8); / / call the function, and the return value is assigned to x

Function myFunction (a, b) {

The return a * b; / / function returns the product of an and b

}

The result of x will be: 56

This is the end of the article on "JavaScript function syntax, function call and function return instance analysis". Thank you for reading! I believe you all have a certain understanding of "JavaScript function syntax, function call and function return instance analysis". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report