Don't understand this syntax found in calculator project

The handleClick method in( https://codepen.io/Snowd3n/pen/yqGaVm) starts:


handleClick = (buttonName) => {

switch(true){

case buttonName === "0" ||  etc.

I’m familiar so far with methods that start:

handleClick(event)
{
do x, y and z
}

It looks like the handleClick method is taking the value of ‘buttonName’ from the button that’s been clicked, and using it in a subsequent method which contains a select case statement.

Also, I don’t understand why switch has an argument set to true: switch(true).

Basically, this code syntax is unfamiliar to me. Could anyone explain or provide a link to an explanation. Thank you.

The switch syntax allows you to specify a value (true in this case) and then a set of case statements. Going from top to bottom, when one of those case conditions matches the value specified, then the statement associated with the matched case executes.

Looking at that codepen, it seems like a perfect example of how NOT to write a calculator app. It’s using the switch statement in a strange way, and the code is really repetitive and not structured very well (no offense to whoever wrote it). It’s not a good example to learn from.
Normally you would use switch case like:


switch (buttonName){
case "0": 
       do something
break
case "1": 
       do something else
break
}

where each case would handle a different value of buttonName, but in this case, the case statements are each handling several values at once, which is not normally how cases are used.