Expressions

Object method definition

Try the free JavaScript compiler

Defines a callable method property with concise syntax. Ordinary methods receive this from the invocation and are not constructors; arrows differ in receiver behavior.

Formal Syntax & Structure

javascript syntaxjavascript
{ method(parameter) { … } }

Working Example

Example Snippetjavascript
const a={n:5,read(){return this.n;}};console.log(a.read());
JavaScript Reference