DEV Community

Discussion on: Switch statements in javascript – How to refactor?

Collapse
 
frankwisniewski profile image
Frank Wisniewski

The day of week was just a example....

console.log( new Date().toLocaleDateString("En-en",{ weekday: 'long' }));
Enter fullscreen mode Exit fullscreen mode
Collapse
 
vbarzana profile image
Victor A. Barzana

Yes sir, I agree with your comment, what I am trying to correct here is about replacing the switch, think of days of the week as fruits, and you will get my point.

Thread Thread
 
frankwisniewski profile image
Frank Wisniewski • Edited

Yes Sir, an array works well for months, days, etc.
The weekday example is not good...

Thread Thread
 
ajayv1 profile image
Ajay Kumar Verma

Updating the code.

Collapse
 
ajayv1 profile image
Ajay Kumar Verma

@frankwisniewski Above was just an example to illustrate how we can acheive the switch statement through JS object.

Thanks for one liner though!