How to return two values in JavaScript?

You cannot return two values in JavaScript, but you can emulate it by returning a two-element array.

Here's how you do it:

const myFunction = () => {
  const a = 1;
  const b = 2;

  return [ a, b ];
};

const [ result1, result2 ] = myFunction();

console.log(result1, result2); // 1 2