Helper Functions

All functions are bound to do a specific task. And whenever a function is used inside a function for certain task they are called as helper functions.

Example:

function multiplyByNineFifths(number) {
    return number * (9/5);
}

function getFahrenheit(celsius) {
    return multiplyByNineFifths(celsius);
}

console.log(getfahrenheit(15));

// Output: 27 

Explanation:

  • getfahrenheit() function get a argument as celsius which is then passed on to the multiplyByNineFifths()

  • When multipluByNineFifths() recieves an argument it passes it on to its inside task

  • When all that is followed we get the final value which is captured and then logs as output.

Another Example:

function monitorCount(rows, columns) {
  return rows * columns;
}

function costOfMonitors(rows, columns) {
  return monitorCount(rows, columns) * 200;
}

const totalCost = costOfMonitors(5, 4);

console.log(totalCost);

// Output: 4000

Last updated