If you’re aiming for a modern and flexible way to format currency, I’d say go with Intl.NumberFormat. It’s built right into JavaScript and super handy.
function formatCurrency(amount) {
return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amount);
}
console.log(formatCurrency(2500)); // $2,500.00
This is my go-to approach when I need a reliable JavaScript format currency solution that also respects localization settings and it’s super readable too!