Course contentsShow
← JavaScript
Lesson 647 of 2,72316. Object Methods and PatternsFree lesson

Method Shorthand Syntax in Object Literals

Learn the concise method definition syntax introduced in ES6 for defining functions as object properties.

Method Shorthand Syntax in Object Literals

What you'll learn: How to write methods in objects more concisely using ES6's shorthand syntax.

The Old Way vs. The New Way

Before ES6, when you wanted to add a method (a function as a property) to an object literal, you had to write it like this:

const calculator = {
  add: function(a, b) {
    return a + b;
  }
};

Notice you had to write both the property name (add) and the word function.

ES6 introduced method shorthand syntax, which lets you drop the colon and the function keyword entirely:

const calculator = {
  add(a, b) {
    return a + b;
  }
};

Same functionality, less typing!

Why It Matters

Think of it like signing your name: the old way is writing out your full formal signature every time, while the shorthand is your quick initials—faster, cleaner, but still valid.

This syntax works exactly the same as the traditional approach. The this keyword behaves identically, and you can call the method the same way:

const user = {
  name: 'Alice',
  greet() {
    return 'Hello, ' + this.name;
  }
};

console.log(user.greet()); // "Hello, Alice"

You can also combine shorthand methods with property shorthand and computed property names for very compact object definitions.

When to Use It

Use method shorthand whenever you're defining methods in object literals. It's cleaner, more readable, and universally supported in modern JavaScript environments. The only reason not to use it is if you need the old function keyword for some edge case (though this is rare).

Key Takeaway: Method shorthand syntax lets you define methods in object literals without the function keyword or colon—write methodName() {} instead of methodName: function() {} for cleaner, more modern code.