

And as a developer, that right there should be your goal. It accomplishes the exact same task, and yet it’s more direct, meaningful, and explicit code that would help a fellow developer joining the project be able to make a quick inference about the intention of the function. The switch takes the argument its fed, a specific friend, and runs through all the various cases we’ve defined until it reaches an exact match, and then executes this block of code.

But as a template, they run something like this: That’s a lot of code jargon, and I’m willing to bet you already know how if statements work. The traditional conditional statement, used with the if statement, executes a block of code, if the conditional parameter fed to the if statement evaluates to the Boolean value true. Sounded like a textbook definition right there, so let’s just say it is a way to structure if conditional statements in a more efficient way, if you are working within the confines of a strict range of values. So Switch/Case has its largest part in areas that necessitate conditional rendering. But if you’re not that familiar yet, don’t beat yourself up really. So, the Switch/Case statement is something that you are probably most familiar with if you frequently use Redux in your projects, because the Reducer logic is constructed with the help of Switch/Case statements. Now let’s talk about the Switch/Case statement.

Ok, so I think the thing that most people forget when working with React is that it’s simply a Javascript library it’s not its own framework with its own unruly syntax and structure, and apart from the JSX returned by components, it’s really just a very powerful, holistic representation of the extents to which you can use Javascript and in that React is just a specific structure and sandbox for the streamlined development of web apps with Javascript, you can really help yourself get the most out of React by getting the most out of Javascript.
