![]() Hard to understand when there is complex logic.Evaluates every case until it finds the right one.In JavaScript, everything is based on curly braces, but not switch.Restrictions, like not allowing to use the same constant in two different cases….You are manually forced to use break within each case.Hard to maintain which leads you to difficult debugging and testing.Now you are asking yourself, then it must be if-else statements, but still, the answer is NO. But since we are talking about JavaScript, have you ever asked yourself if it is clever to use it? We all know what is a switch – case statement and we used them at least one time in our life, no matter which programming language. In this blog, I will explain some of the object features and I will make some comparisons, so let’s start! Switch vs object literals That was the main reason why I decided to write a blog about it, so I really hope in near future most of your obstacles will be resolved and you will be more confident in choosing which is the best approach. During the development, we use objects and we are always confused which approach is the best.
0 Comments
Leave a Reply. |