'Why can we assign console.log to a variable

I am confused how we can assign console.log(`${tempCel} to ${tempFar}. What are we truly displaying?

const tempCel = Number(prompt("Enter a temperature in Celsius degrees:"));
const tempFar = tempCel * 9 / 5 + 32;
console.log(`${tempCel}°C = ${tempFar}°F`);


Solution 1:[1]

To assign to a variable means to give the variable some value. It's usually done with = operator.

For example:

const variable = 5;
const variable2 = "Some text";

We cannot assign console.log() - it will always be undefined.

What you are doing is using a template literals inside the console.log()

You can learn more about template literals here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 marian150