Helper function

Hi, I’m literally struggling with Helper. In these lines ( I invente to practice) , sths wrong but I can’t see it. Would you help me? I’d also appreciate a brief explanation of how these funbtions work and why would I need them. The one in the lesson wasn’t 100 % clear for me . Thks in advance!

function areaHab (largo,ancho){
return largoancho;
function areaCasa(largo,ancho){
return areaHab(largo
const numeroFinal=areaCasa (2,4);

A ‘helper function’ is still just a function we would expect to be able to call from anywhere in our program to perform a specific task. It will not interact with the outer scope, and will have no side effect. The inputs we give it all have predictable return values.

const rectArea = function (l, w) {
    return l * w;

Let’s pretend we have a function that computes and adds the areas of several rectangular segments to arrive at a single return value, ‘totalArea’. Consider the area under a curve taken in thin slices, for instance.

The helper function above will be called several times from within the above described function. This is why we can refer to it as a ‘helper’, as it abstracts away the multiplication operation and lets us pass value pairs to compute each segment.

Bottom line, ‘helper function’ is not anything special, apart from that we have abstracted it away from our function and freed it up in our main code base so that it’s utility can be exploited by other functions.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.