Get the App
SLTechnology News&Howtos  ›  Development  › 

How to execute the code inside the JavaScript function

Shulou Source: shulou.com Published: 2022-06-01 04:58:04 09月21日 Update

This article mainly introduces "how to execute the code inside the JavaScript function". In the daily operation, I believe that many people have doubts about how to execute the code inside the JavaScript function. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to execute the code inside the JavaScript function". Next, please follow the editor to study!

The code inside the JavaScript function executes when it is called

Call the JavaScript function

When a function is defined, the code inside the function does not execute.

When a function is called, the code inside the function is executed.

Calling a function can also be said to "start the function" or "execute the function".

In this tutorial, we use call.

Call a function as a function

Example

Function myFunction (a, b) {

Return a * b

}

MyFunction (10, 2); / / will return 20

The above functions do not belong to any object. But in JavaScript, there is always a default global object.

In HTML, the default global object is the HTML page itself, and all the above functions "belong" to the HTML page.

In the browser, the page object is the browser window. The above function automatically becomes a window function.

MyFunction () and window.myFunction () are the same function:

Example

Function myFunction (a, b) {

Return a * b

}

Window.myFunction (10, 2); / / also returns 20

At this point, the study on "how to execute the code inside the JavaScript function" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Functions code objects learning pages global instance more browser faceted help browsing utility and then forms tutorials articles methods are in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS Microsoft OPPO Reno Xiaomi