Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use number range in switch/case by JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:01:00 10月04日 Update

Editor to share with you how JavaScript uses digital ranges in switch/case, I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.

Using numeric ranges in switch/case

In fact, the case condition in switch/case can also be written as follows:

Function getCategory (age) {var category = ""; switch (true) {case isNaN (age): category = "not an age"; break; case (age > = 50): category = "Old"; break; case (age)

Tags: Intervals numbers articles content communication learning not much front end most learning exchanges more conditions welcome to join knowledge industry information information channels channels references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker Huawei Redmi NVidia