

Hello James, really nice question.
In JavaScript, the easiest way to make the output look cleaner with a dollar sign is to format it as a string. A very common way to do that is with a template literal (using backticks `):
let costPrice = 25;
let sellPrice = 35;
let profit = sellPrice - costPrice;
console.log(`Profit: $${profit}`);
Whatâs happening here:
The backticks let you write a string with embedded expressions.
${profit}is replaced by the actual value ofprofit.The
$before it is just a normal character in the string, so it shows up exactly as youâd expect.
You could also do it with string concatenation:
console.log("Profit: $" + profit);
Both work, but template literals are usually cleaner and easier to read, especially as the text gets longer.
If you have further questions, I'm here to help.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
