Javascript Function Return Object

Description

Javascript Function Return Object


// Returning a complex object
function addTwoNumbers(x,y) {
    return {result:(x+y), originalX: x, originalY: y};
}
let sumResult = addTwoNumbers(9,3);
console.log("Sum: " + sumResult.result + " (comes from adding " + sumResult.originalX + " and " + sumResult.originalY + ")");



PreviousNext

Related