tgoop.com/frontend_1/3887
Create:
Last Update:
Last Update:
💡Использование switch (true) в JavaScript
Большинство JavaScript-разработчиков знакомы с оператором switch
(документация MDN), но для тех, кто только начинает изучать язык, давайте кратко разберём, как он работает.
Оператор switch
позволяет сравнить выражение с одним из нескольких возможных случаев (case):
city = "London";
const getCountryByCity = () => {
switch (city) {
case "Edinburgh":
return "Edinburgh is the capital city of Scotland";
case "Madrid":
return "Madrid is the capital city of Spain";
case "London":
return "London is the capital city of England";
default:
return "Cannot find which country this city is the capital of.";
}
};
https://seanbarry.dev/posts/switch-true-pattern
👉 @frontend_1
BY Frontend разработчик

Share with your friend now:
tgoop.com/frontend_1/3887