프론트엔드 공부/javscript
switch 열거문
maggieH
2021. 4. 28. 23:19
const Direction = {
UP:'UP',
DOWN:'DOWN',
LEFT:'LEFT',
RIGHT:'RIGHT'
};
function sayDirection(direction){
switch(direction){
case Direction.UP :
console.log('we are going up');
break;
case Direction.DOWN :
console.log('we are going down');
break;
case Direction.LEFT :
console.log('we are going left');
break;
case Direction.RIGHT :
console.log('we are going right');
break;
}
};
sayDirection(Direction.UP);
//we are going up
각 케이스별 조건을 걸고 싶은 경우,
타입스크립트에서 자주 사용함.