This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by SHaon
*Old Ways *
const getPrice = (item) => {
if(item==200){return 200}
else if (item==500){return 500}
else if (item===400) {return 400}
else {return 100}
}
console.log(getPrice(foodName));
New Ways
const prices = {
food1 : 100,
food2 : 200,
food3 : 400,
food4 : 500
}
const getPrice = (item) => {
return prices[item]
}
console.log(getPrice(foodName))
Hope you like my new tricks :D
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by SHaon
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
SHaon | Sciencx (2022-10-04T04:52:35+00:00) New Usefull JavaScript Tips For Everyone. Retrieved from https://www.scien.cx/2022/10/04/new-usefull-javascript-tips-for-everyone/
" » New Usefull JavaScript Tips For Everyone." SHaon | Sciencx - Tuesday October 4, 2022, https://www.scien.cx/2022/10/04/new-usefull-javascript-tips-for-everyone/
HARVARDSHaon | Sciencx Tuesday October 4, 2022 » New Usefull JavaScript Tips For Everyone., viewed ,<https://www.scien.cx/2022/10/04/new-usefull-javascript-tips-for-everyone/>
VANCOUVERSHaon | Sciencx - » New Usefull JavaScript Tips For Everyone. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/04/new-usefull-javascript-tips-for-everyone/
CHICAGO" » New Usefull JavaScript Tips For Everyone." SHaon | Sciencx - Accessed . https://www.scien.cx/2022/10/04/new-usefull-javascript-tips-for-everyone/
IEEE" » New Usefull JavaScript Tips For Everyone." SHaon | Sciencx [Online]. Available: https://www.scien.cx/2022/10/04/new-usefull-javascript-tips-for-everyone/. [Accessed: ]
rf:citation » New Usefull JavaScript Tips For Everyone | SHaon | Sciencx | https://www.scien.cx/2022/10/04/new-usefull-javascript-tips-for-everyone/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.