1 year ago

#254530

test-img

Efrain Mejia

Replacing switch statement with Object literal with booleans

I have this switch statement where a, b, c and d can be true or false, but only one of them is going to be true, and when one of them is true it returns X which is a variable. How can I replace this switch statement with an object literal?

switch (true) {
        a: return x
        b: return x
        c: return x
        d: return x
      }

switch-statement

javascript-objects

object-literal

0 Answers

Your Answer

Accepted video resources