Don´t use switch

It is valid JavaScript code.

const stackComponent = 'client';
let tech = '';

if( stackComponent === 'client') {
	tech = 'JavaScript'
} else if (stackComponent === 'server') {
	tech = 'Node'
} else if (stackComponent === 'API') {
	tech = 'GraphQL'
} else {
	tech = 'MongoDB'
}

Instead of writing many if..else statements, you can use the switch statement.

const stackComponent = 'client';
let tech = '';

switch(stackComponent) {
	case 'client':
		tech = 'JavaScript'
		break
	
	case 'server':
		tech = 'Node'
		break
		
	case 'API'
		tech = 'GraphQL'
	
	default:
		tech = 'MongoDB'
}

But there is an approach with fewer lines of code and more scalable

const stackComponent = 'client';

const languages = {
	'client': 'JavaScript',
	'server': 'Node',
	'API': 'GraphQL',
}

const languageDefault = 'MongoDB';

const code = languages[stackComponent] || languageDefault;
console.log(code);
// expected output: 'JavaScript'
Powered by Forestry.md