Get the App
SLTechnology News&Howtos  ›  Development  › 

How to define JavaScript function

Shulou Source: shulou.com Published: 2022-06-01 10:31:06 11月01日 Update

This article mainly introduces the relevant knowledge of how to define the JavaScript function, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to define the JavaScript function. Let's take a look.

JavaScript uses the keyword function to define functions.

A function can be defined by a declaration or an expression.

Function declaration

In the previous tutorial, you learned about the syntax of function declarations:

Function functionName (parameters) {

Executed code

}

The function will not be executed immediately after it is declared, but will be called when we need it.

Case study

Function myFunction (a _ r _ b) {

Return aquib

}

Note semicolons are used to separate executable JavaScript statements.

Because the function declaration is not an executable statement, it does not end with a semicolon.

Function expression

The JavaScript function can be defined by an expression.

Function expressions can be stored in variables:

Case study

Var x=function (aformab) {return aforb}

After a function expression is stored in a variable, the variable can also be used as a function:

Case study

Var x=function (aformab) {return aforb}

Var Zhonx (4pr 3)

The above function is actually an anonymous function (the function has no name).

Functions are stored in variables, do not require a function name, and are usually called through the variable name.

This is the end of the article on "how to define JavaScript functions". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to define JavaScript function". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Functions variables expressions instances knowledge storage content semicolons can be passed through names articles statements code values keywords keywords actually easy to operate tutorials Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS vpn Docker Redmi