Skip to content
N-Mate

N-Mate

AngularJS programming

  • Home
  • About
  • Media
  • Contact
  • Home
  • Angular JS
  • Problems with switch
Angular JS
Writing a mini blog with $routeParams in AngularJS
03/03/2022
Angular JS
HRM Software: Empowering Modern Human Resource Management
24/07/2023
Angular JS
How to Audit a Link Building Agency’s Past Work Before You Hire Them
08/07/2025
Angular JS
Getting Started with AngularJS: A Beginner’s Guide to Coding
07/03/2023
Angular JS
What is Angular
22/05/2022
Angular JS
9 top AngularJS frameworks
11/07/2022

Problems with switch

Posted on 27/04/202208/09/2022 By Roy
Angular JS

There are many unpleasant things about using switch: the procedural control flow, the non-standard syntax of code blocks – in javascript, curly braces are used as standard, in the switch construct they are not. In general, switch syntax is not the best example of javascript. We have to manually add a break for each case, which can make it hard to debug errors later, and if we forget a break somewhere, it triggers errors in subsequent case cases. Douglas Crockford has written and talked about this many times; he recommends using switch with caution.

In javascript we often use objects for all sorts of things, including things we wouldn’t dream of using switch. So why not use an object literal instead of the switch? It would make our code more flexible, readable, maintainable, and we wouldn’t have to manually add break to our cases! It also makes it easier for newbies to work, since they are standard objects.

As the number of cases increases, the performance of objects (hash tables) becomes better than the switch construct (where consistency of cases is important). The object approach is a hash table lookup, and the switch construct has to evaluate each case until it finds a match and break.

Post navigation

❮ Previous Post: Writing a mini blog with $routeParams in AngularJS
Next Post: What is Angular ❯

You may also like

Angular JS
Getting Started with Angular
15/06/2022
Angular JS
9 top AngularJS frameworks
11/07/2022
Angular JS
Solana vs Ethereum: The Battle for Leadership in the World of Smart Contracts
08/08/2024
Angular JS
What’s the power of Angular
09/08/2022

Recent Posts

  • How to Audit a Link Building Agency’s Past Work Before You Hire Them
  • Why Python Remains One of the Most Popular Programming Languages
  • Solana vs Ethereum: The Battle for Leadership in the World of Smart Contracts
  • HRM Software: Empowering Modern Human Resource Management
  • The Benefits of Using Angular Animations for Mobile App Development

Archives

  • July 2025
  • August 2024
  • July 2023
  • June 2023
  • March 2023
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022

Gallery

Progressive Web Apps with Angular

https://www.youtube.com/watch?v=51Nd_mTpugY&list=PL0vfts4VzfNjsTV_6i9a9iczMnthWqHzM&index=7

Nx Quickstart – How to Scale a JavaScript Project

https://www.youtube.com/watch?v=VUyBY72mwrQ&list=PL0vfts4VzfNjsTV_6i9a9iczMnthWqHzM&index=8

Angular for Beginners – Let’s build a Tic-Tac-Toe PWA

https://www.youtube.com/watch?v=G0bBLvWXBvc&list=PL0vfts4VzfNjsTV_6i9a9iczMnthWqHzM&index=9
  • Facebook
  • Twitter
  • Instagram
  • Email
  • facebook
  • twitter
  • instagram
  • youtube

Copyright © 2025 N-Mate. Privacy Policy