Switch Case Over Ranges in JavaScript 🤩

preview_player
Показать описание
How to use greater than and less than in a switch statement in JavaScript.

📣 Follow Coding in Flow on social media:
Рекомендации по теме
Комментарии
Автор

Was badly looking for a proper reason why we use ‘true’ in switch expression finally got urs! Thank you

vidhyamanoharan
Автор

I tried to do this several times in JS, but I was not aware that we had to write ‘true’ as the expression. So I thought this was not possible. Most helpful video ever!!

deepindersingh
Автор

This improves readability but you are doing an extra comparison each time this code is executed comparing to the if-else chain

lucas.codes.tutorials
Автор

didn't switch case only compare equality?

JuanPabloHernandezRamirez-se
Автор

use ts-pattern
believe me you'll love it

rimzzlabs
Автор

Can we do it in java or python as well?

ayushsharaf
Автор

Nice one ...just let me out of my headache lol

tsheringyangden
Автор

ok but why even do this if you could remove the unnecessary brackets of the else if statements. It would be just as clean as the switch but 2 less lines

sorenschultz
Автор

I presume this is bad practice, but nice to know anyway

pepehimovic