DEV Community

Discussion on: Do's and Don'ts for Javascript Newbies

Collapse
 
tamouse profile image
Tamara Temple

Formatting code: Prettier is something folks should know about; it integrates with ESLint quite nicely, and can be added to most code editors pretty easily.

let, const, and var: In the examples given, doing let container = document.getElementByID('SomeId') is more of a signal to the developers that it will somehow be changing. In fact, the variable itself never changes, it still points to the same DOM element object, which is changing internally. This can be hugely confusing to realize that const container = document.getElementById('SomeId') ; container.innerHTML = "Hello" will work exactly the same way. Kyle Simpson (@getify) has a great discussion on this in YDKJS.

Also, don't completely discard var from your vocabulary as it still has uses; instead understand when and where to apply it.

The adage "use const until you can't" is a good one if everyone understands that.

Great article!

Collapse
 
juliavii profile image
juliavii

I come to the comments looking for an explanation about the let/const and why we should use them instead of var.

Can you clarify the difference for me?

Collapse
 
tamouse profile image
Tamara Temple

No where near as well as Kyle does: github.com/getify/You-Dont-Know-JS...

Collapse
 
jelenakalaba profile image
JelenaKalaba

Thank you.

Collapse
 
qm3ster profile image
Mihail Malo

Came here to make literally these two comments!