JS 0x01 - Multiple Return Values in JavaScript

Since ES2015, a much better way to express multiple return values is available.
1 min read

We’ve all seen functions that look something like this:

function Coord3D(x, y, z) {
  // Some operations to edit the parameters, apply default values, etc.

  // Return a bunch of values
  return {
    x: x,
    y: y,
    z: z
  }
}

Since ES2015, you can refactor the above code to something like this, which is a little more readable:

function Coord3D(x, y, z) {
  // Some operations to edit the parameters, apply default values, etc.

  // Return a bunch of values
  return { x, y, z }
}

Change Log

  • 3/23/2017 - Initial Revision
  • 6/21/2024 - Set status to Published

Found a typo or technical problem? file an issue!