A method in JavaScript is a function defined inside a class body.
This page covers Method in JavaScript. For a language-agnostic introduction, see Method.
Defining a Method#
Methods in a JavaScript class are written without the function keyword — just the name, parentheses, and body.
class Player {
greet() {
console.log("Hello!");
}
}By convention, method names use camelCase: greet, play, getScore.
Return Values#
Use return to send a value back. A method without a return statement returns undefined.