I don't understand the syntax $ or when to use it

const calculateSleepDebt = () => {
  var actualSleepHours = getActualSleepHours();
  var idealSleepHours = getIdealSleepHours();
  if (actualSleepHours === idealSleepHours) {
    console.log('Perfect amount of sleep.');
    } else if (actualSleepHours < idealSleepHours) {
     console.log(`Not enough sleep. ${idealSleepHours - actualSleepHours} hours of sleep missing`);
    } else if (actualSleepHours > idealSleepHours) {
      console.log(`More than enough sleep. ${actualSleepHours - idealSleepHours} hours of sleep you don't need.`);
    } else {
     console.log('Unsure') 
    }
};
calculateSleepDebt();

In this example, why do you need to use the $ and what does it acutally do? I haven’t really understood this yet. And also, when the $ symbol is used, one needs to use the ` instead of normal ’ correct?

Thanks for your help!

${} allows us to insert variable into a string. The string then needs to be enclosed in backticks (grave accent)

1 Like

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