"create another variable"

Hi, i’am pretty fresh in JavaScript learning, and i can’t get why we need to create new variables all the time ? Here is quick example from sleep debt project

const calculateSleepDebt = () => {
    const actualSleepHours = getActualSleepHours();
    const idealSleepHours = getIdealSleepHours();

Why i can’t just compare one function with another, insted of that i need to create new variables which are equal to function ?
When i’am comparing functions it’s work, so what’s the point?

In case of this exercise, you might be right: You could just write something like:

if(getActualSleepHours() < getIdealSleepHours()) {
 return 'You must be tired'

But in general you might want to reuse the return value of a function more often. Then you wouldn’t want to repeat the function call because that needs more resources than using the stored value.

Please always post a link to the lesson

1 Like

Ok, now it’s clear when you explained that :slight_smile:

1 Like