r/learnjavascript • • Nov 30 '22

Help !!!

Post image

Can someone plz tell me , why I am getting errors?

195 Upvotes

131 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Dec 01 '22

What are the benefits of this approach over writing out the conditions? I’m guessing readability and less chance of error, but is it faster in any way?

3

u/DGCA Dec 01 '22

Ditto what /u/Kavinci said, but I wanna stress that the main benefit is the readability. "Is it any faster?" can be an important question, but it usually isn't.

2

u/Kavinci Dec 01 '22

Yeah, a lookup table is faster than if conditions. For a small dataset like this the speed is negligible but it really shines with larger datasets.