DEV Community

Cover image for Common JavaScript Mistakes in 2024
Shariq Ahmed
Shariq Ahmed

Posted on

Common JavaScript Mistakes in 2024

So, it’s been a long time for me to be in the industry. So, I know what are some common mistakes that developers make in JavaScript. These mistakes are most common among people who are a beginner in JavaScript. Again, the reason is pretty obvious — they don’t know JavaScript fully.

1. Not Mentioning Return in Function

If you just call a function without mentioning return, then there’s 100% chance that you’ll get ‘undefined’ in result. Why? Well, JavaScript functions give ‘undefined’ by default. This means you need to mention ‘return’ explicitly to get the result.

2. JavaScript Loading Before DOM is Loaded

This is another most common mistake made by people who are learning JavaScript: loading JavaScript scripts before DOM is loaded.

3. Considering JavaScript as Complete Synchronous

Developers coming from C, C ++, python, and Java mostly make this mistake. They think that in JavaScript, there would be line by line code execution. But that’s not the case. There are some things in JavaScript that are synchronous. While other things are asynchronous. So, make sure you know what’s non-blocking, blocking, async, await, promise, etc.

4. Sure, JavaScript is Forgiving But…

This doesn’t mean that it’s completely forgiving. But wait. What does it mean by forgiving? Well, unlike in python, if you miss a semicolon in JavaScript, then you won’t get an error. JavaScript will still execute. But this doesn’t mean you should completely stop using semicolons in JavaScript. Keep in mind that code pollution is a bad thing. It will not only impact code readability but you will yourself become confused.

5. Not Learning Modern JavaScript

JavaScript was created in 1995 by Brendan Eich. But with time, many new methods have been added in JavaScript. So, it’s important for you to know those methods. Because a lot of those methods actually improve code readability.

6. Unsecure Code

It’s essential to make your code secure. But how? Well, avoid making unnecessary functions. Further, instead of using functional programming, prefer class-based programming.

Top comments (0)