I couldn't find any documentation or questions about whether it's possible to write the case
statements in a switch statement on one line nor what the best practice and way to write them on one line in JavaScript is.
The most related questions were: CodeGrepper Question and Switch statement for multiple cases in JavaScript
I currently have a function with a switch statement that returns a product's name:
function returnProduct(product) {
switch (product) {
case 'aa': case 'AApple':
return 'AApple';
case 'bb': case 'BananaBall':
return 'BananaBall';
case 'ee': case 'ElephantElf':
return 'ElephantElf';
default:
return 'Sorry we don\'t have that yet';
}
}
console.log(returnProduct('aa'));
console.log(returnProduct('error'));
console.log(returnProduct('ee'));
console.log(returnProduct('BananaBall'));