Most Common Mistakes JavaScript Developers Make

1.Using “==” instead of “===”

 This is probably the most common error when people start with JS. The difference between the two is that “==” will convert the type and “===” will not.

2. Omitting Semi-Colons

JavaScript does add semi-colons if they are omitted but it can actually mess up your code and cause strange errors. Here are the two most popular cases:

3.Avoid new object()

Avoid creating a new object by using new Object(). Use the object literal syntax {} instead.

4.use setTimeout and setIntervel

Always pass functions to setTimeout and setInterval during development

5.Using “this” incorrectly in a class

This is probably the most common blocking point for people getting started with JavaScript when they come from a language like Java. In Java, “this” always refers to the current object. This is not the case in JavaScript. In fact, “this” has 5 different ways of being bound.

6.Confusing Addition & Concatenation

Addition is about adding numbers.

Concatenation is about adding strings.

In JavaScript both operations use the same + operator.

Because of this, adding a number as a number will produce a different result from adding a number as a string:

7.Misunderstanding Floats

All numbers in JavaScript are stored as 64-bits Floating point numbers (Floats).

All programming languages, including JavaScript, have difficulties with precise floating point values:

8.Misplacing Semicolon

sometimes you put semicolon after if condition if(); brackets like this

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post