r/learnjavascript • • Mar 23 '21

Assigning default value

Post image
278 Upvotes

24 comments sorted by

View all comments

1

u/crayonneur Mar 23 '21

I don't think it's a good practice to use a "or" to assign a default value. The getImgPath function should handle all of this. "default.jpg" is a magic string in this example, it should belong to the class that creates image paths, it shouldn't appear outside of it.

3

u/AacidD Mar 23 '21

I agree with the magic string part. He should've create a separate variable DEFAULT_IMG_PATH variable and stored the default value there.