Sitemap

codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Avoid These Common JavaScript Mistakes

4 min readSep 9, 2020

--

Press enter or click to view image in full size
Photo by NeONBRAND on Unsplash

Out of the many scripting languages, JavaScript is a great option for beginners to learn. However, this does not mean that it is an easy language or that you won’t make mistakes when writing code. In this article, I will cover some of the most common JavaScript mistakes that beginners make with the intention of helping you avoid them.

Referencing code before it’s loaded

JavaScript loads and runs the code in the order in which it appears in the document. If you have a script defined in the head HTML tag that accesses the HTML element(s) on the page, an error will be thrown. The following is an example of this mistake:

To avoid making this mistake when your script relies on the HTML elements on the page, either put the JavaScript code at the end of the file, or load the JavaScript file and add an attribute (such as “defer to the script” tag). Below is an example of using the defer attribute:

Defer Attribute — This tells the browser to download only the scripts and only executes scripts after parsing the HTML file.

Using == and === Operators incorrectly

These are both comparison operators and return boolean values. The double equal operator (==), also known as a comparison operator, is used to compare two…

--

--

codeburst
codeburst

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Taran
Taran

Written by Taran

I am a Full stack developer. I enjoy learning and building new skills, and sharing what I’ve learned.

No responses yet