Home>Article>Web Front-end> What are the keywords used to define methods in javascript
The keyword for defining methods in JavaScript is function; the syntax for using the function keyword is such as "function functionName(parameters) {executed code}".
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!