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

How to call a function by JavaScript operator

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this article "JavaScript operator how to call function", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "JavaScript operator how to call a function" article.

You can reuse the code: as long as you define the code once, you can use it multiple times.

You can pass different parameters to the same function multiple times to produce different results.

Example

Convert Fahrenheit to Celsius:

Function toCelsius (fahrenheit) {

Return (5ax 9) * (fahrenheit-32)

}

Document.getElementById ("demo"). InnerHTML = toCelsius (77)

() operator call function

Using the above example, toCelsius refers to the function object, while toCelsius () refers to the function result.

Example

Accessing a function without () returns the function definition:

Function toCelsius (fahrenheit) {

Return (5ax 9) * (fahrenheit-32)

}

Document.getElementById ("demo"). InnerHTML = toCelsius

A function used as the value of a variable

Functions are used in the same way as variables, in all types of formulas, assignments, and calculations.

Example

Use variables to store the value of the function:

Var x = toCelsius (77)

Var text = "The temperature is" + x + "Celsius"

You can use the function directly as a variable value:

Var text = "The temperature is" + toCelsius (77) + "Celsius"

You will learn more about functions in this tutorial.

Local variable

Variables declared in the JavaScript function become local variables of the function.

Local variables can only be accessed within a function.

Example

/ / the code here cannot use carName

Function myFunction () {

Var carName = "Volvo"

/ / code here CAN use carName

}

/ / the code here can use carName

Because local variables can only be recognized by their functions, variables with the same name can be used in different functions.

Local variables are created at the beginning of the function and are deleted when the function is completed.

The above is the content of this article on "how to call the function of JavaScript operator". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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