룩업테이블1 Lookup Table if - else if - else를 switch로 리팩토링하는 케이스는 엄청 흔하다. function getChannelType(channelType) { switch(channelType) { case "A": return "A 채널"; case "B": return "B 채널"; case "C": return "C 채널"; default: return "채널 없음"; } } 근데 이걸 이렇게도 할 수 있다. function getChannelType(channelType) { const CHANNEL_TPYE = { A: 'A 채널', B: 'B 채널', C: 'C 채널', }; return CHANNEL_TYPE[channeltype] || '채널 없음'; } case와 return문이 한 줄에 .. 2022. 9. 5. 이전 1 다음