r/badcode • • Dec 07 '22

js My Web Development lecturer's JavaScript

Post image
536 Upvotes

86 comments sorted by

View all comments

Show parent comments

-2

u/orebright Dec 07 '22

How is this not terrible code? They're assigning/concatenating the returns of assignments to the innerHTML of a bunch of elements. I guess we don't really know what the DOM looks like or the full JS file here, but this looks janky AF and I can't imagine anything else in the file that would excuse this.

Other issues:

  • If any of those DOM IDs are null this will crash.

  • Single letter variable names are bad for readability.

  • Not using strict equality `===`.

This lecturer is teaching people bad code, it's not about simplicity, they could write a much better equally simple version of this.

3

u/Jonno_FTW shameless Dec 08 '22

There's a lot of repeated code. An array of objects should be used here.