Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Opinion on best practice checklist

Needed some opinion on a set of checklist for reviewing my code, my goal is below:

Modularised code so I can easily maintain & reuse:

but I am a real novice with Javascript, and I am trying to translate my experience with other language into this and I am not sure if my assumptions are 100% correct in JS context, would really appreciate any opinion at all:

Some checklist item below:

1a) All major element that needs to use document.getElementByX (or querySelector) should be declare as a global const at the script startup.

and that leads to...

1b) A function should not finding any element using document; Instead the function should pass a parameter element that is already declared, and every other element within the function will be declare as a relative DOM item to that target.

2a) All element object generated by function should have a class name (or maybe all element in general, except maybe simple ones like <p>)

and that leads to...

2a) If a parent element contains multiple child input/button element, the parent's event handler should always check for input / button using class name, and specifically not using tag name or text content.