Sign in Go Pro

Beginning JavaScript for React Native

Switch / Case Statement


Up next



The switch/case statement is another way to branching in JavaScript. It is an alternative to an if/else block - but it is also more flexible than if, because it can check for any value of the switching variable - and not just true or false.

Switch/case is often used in React applications in Redux reducers - which are often big functions with a single switch/case, which represents the entire function.

Summary of Content:

  • Defining a simple switch statement and a few case blocks
  • Preventing "fall through" with break or return
  • Switch checks against value and type (===)
  • Using default to provide a default return value from switch/case





There are no comments on this lesson, start the conversation below ...

You need to go PRO to post comments.

Lessons in Beginning JavaScript for React Native