The keyword used to define a function in JavaScript is function. You can create a function using the following syntax:
function functionName() {
// Function body or code block
}
javascript复制成功复制代码
Alternatively, you can also define functions using arrow function expressions (introduced in ES6) as follows:
const functionName = () => {
// Function body or code block
}
javascript复制成功复制代码
Both of these syntaxes allow you to define a function in JavaScript.