DEV Community

Discussion on: Looking for JavaScript/jQuery Resources to Write Cleaner, Concise Code (Code Examples Provided)

Collapse
 
sualko profile image
Klaus Herberth

For me the book "clean code" was an eye opener. It's a bit extreme, but the fundamentals are awesome. The most important point is to have small functions with good names. This helps you to structure your code and improves readability.

For example I would move the add/remove class line to it's own function. Personally I also don't like the chaning, because it's terrible to read. Also move all const to the outside of your function. Document ready inside a function is also pretty unusual.

Your code, espacially the template part, could be improved by using string literals.

Happy coding and I hope we will see an refactored version.

Collapse
 
mjericsson profile image
Matt Ericsson

This is exactly what I was hoping to hear.

The add/remove class recommendation makes total sense, I just hadn't thought of it that way. The chaning is something I want to try and avoid and make the code more generic. Good point on the document ready, I'll have to make an adjustment.

Excellent point on string literals, I could definitely utilize that to improve the readability.

Appreciate the insight!