JavaScript Tip: Replace Switch Statements With Object Literals

preview_player
Показать описание
I prefer using JavaScript's object literals over switch statements as the code is faster, more readable, and less verbose.
Рекомендации по теме
Комментарии
Автор

Excellent content, I am working with JS a lot lately (my background is backend basically) and this info in priceless!

Best Regards,
JB

juanalbertoboada
Автор

using switch buried inside a function to basically emulate enums (or Maps) is indeed a weired approach;
never done this and can't recall to have seen this usecase implemented like this anywhere in any language.


I find the switch syntax pretty simple as use switch since ever and plenty to simplify a bulk of complex if-statements _to do stuff_ not necessarily to return some value (maybe `this` for chaining)


Kurzum: das "Problem" hier wirkt etwas konstruiert aber ich mag deinen Blog 🙂

CirTap