FRONTEND_1 Telegram 3887
💡Использование 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



tgoop.com/frontend_1/3887
Create:
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

View MORE
Open in Telegram


Telegram News

Date: |

1What is Telegram Channels? ‘Ban’ on Telegram 5Telegram Channel avatar size/dimensions With Bitcoin down 30% in the past week, some crypto traders have taken to Telegram to “voice” their feelings. Some Telegram Channels content management tips
from us


Telegram Frontend разработчик
FROM American