-
Notifications
You must be signed in to change notification settings - Fork 0
Code Refactoring
Biswajit Sundara edited this page Mar 3, 2021
·
2 revisions
We can make use of objects instead of switch and achieve the same result. Object will look more cleaner and easy to maintain however please note switch case is the best in terms of performance.
function getCurrency(country) {
var currency = {
'India': 'Rupee',
'United States': 'Dollar',
'Europe': 'Euro',
'default': 'Invalid Choice'
};
return (currency[country] || currency['default']);
}
let currency = getCurrency('India');
console.log(currency);