Home>Article>Web Front-end> What are the keywords used to define methods in javascript

What are the keywords used to define methods in javascript

藏色散人
藏色散人 Original
2021-05-11 10:28:18 6295browse

The keyword for defining methods in JavaScript is function; the syntax for using the function keyword is such as "function functionName(parameters) {executed code}".

What are the keywords used to define methods in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

JavaScript function definition

JavaScript uses the keyword function to define functions.

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

Function declaration

In the previous tutorial, you have already understood the syntax of function declaration:

function functionName(parameters) { 执行的代码 }

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

Example

     

本例调用的函数会执行一个计算,然后返回结果:

Output:

本例调用的函数会执行一个计算,然后返回结果: 12

Recommended study: "javascript Advanced Tutorial"

The above is the detailed content of What are the keywords used to define methods in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn