Skip to content
Advertisement

how to concatenate function with javascript closure and object

i’m trying to find a solution to this exercise:

Implement the calculate function that adds an object that gives the ability to do the four mathematical operations (addition, subtraction, multiplication and division) on the same number and finally print out the result.

JavaScript

so, what is the right way to solve this (and if you can add comment will be appreciated

Advertisement

Answer

You can return the object itselft.

JavaScript

Make sure to understand how this works in JavaScript. For instance, using functions is different than using arrow functions.

Reference: JavaScript this

Alternative solution using closure

JavaScript
Advertisement