how to return multiple values in function javascript code example
Example 1: return more than 1 value from function js
//Function that returns multiple values - Using destructuring
function foobar(foo, bar) {
return [foo, bar];
}
const [one, two] = foobar(1, 2);
Example 2: return multiple values in javascript
function getNames() {
// get names from the database or API
let firstName = 'John',
lastName = 'Doe';
// return values
return {
firstName,
lastName
};
}