Object with anonymous functions in JavaScript
In the previous lesson, we made an array consisting of functions. Let's now instead of an array make an object with keys whose values will be functions:
let obj = {
func1: function() {console.log(1)},
func2: function() {console.log(2)},
func3: function() {console.log(3)},
};
Let's use our object:
let obj = {
func1: function() {console.log(1)},
func2: function() {console.log(2)},
func3: function() {console.log(3)},
};
obj.func1(); // shows 1
Make an object with three functions.
Let the first return through return
the number 1, the second - the
number 2, the third - the number
3. Using the created functions,
print the sum of the returned numbers
to the console.
Loop through the created object and output the results of the functions work to the console.