“Javascript” if then else tip

To avoid big if then else chains, today tip with

switch(true)

var i = 0;
switch(true) {
case i === 1:
console.log(i);
break;
case i === 2:
console.log(i);
break;
default:
console.log(i);
break;
}

Thx ;)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.