-3
 const menu = {
    _courses : {
        _appatizers: [],
        _mains: [],
        _deserts: []
    },


get courses() {
    return {
        appatizers: this._courses._appatizers;
        mains:  this._courses._mains;
        deserts:  this._courses._deserts;
    };
}

I am more concerned by how this return is used as an object; please explain as much you can to clarify the concept, thank you. forget about the code.

N8888
  • 670
  • 2
  • 14
  • 20

2 Answers2

0

The return statement does exactly that: returns a value from a function. The return value can be any type, not only an object.

function returnNumber(){
    return 1;
}

function returnString(){
 return 'My string';
}

function returnObject(){
    return {a: 'one', b: 'two'}
}

All of the previous are valid, but you can do the same with arrays, or even return functions from functions...

If you don't explicitly return something from a function, it will implicitly return undefined.

Damian Peralta
  • 1,846
  • 7
  • 11
0

With return you can do exactly what it says: return something. This can be anything: a number, a string, an variable, an array, an object (...).

So in your case, the function returns an object.

A more simple example:


function someNumber() {
  return 42;
}

var number = someNumber(); // somerNumber() will return 42, so number will have the value 42
console.log(number);

For a way more detailed reference, you may want to take a look at this.

CodeF0x
  • 2,624
  • 6
  • 17
  • 28