An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
October 4, 2022 04:52 am GMT
Original Link: https://dev.to/shaon07/new-usefull-javascript-tips-for-everyone-1389
New Usefull JavaScript Tips For Everyone
*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
Original Link: https://dev.to/shaon07/new-usefull-javascript-tips-for-everyone-1389
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To