10 Famous Bugs in JavaScript

img JavaScript is a lightweight, and one of the powerful programming language.
JavaScript growing rapidly on the web world and considered very popular among the web developer.
Right now, JavaScript used in almost every modern web application and JavaScript having the most active projects on GitHub.

There are around thousands of JavaScript developer in the world and every developer make some mistake.
Sometimes our mistakes are as bigger that they cause the program to not producing required result and sometimes our program does not execute at all.
Here is the 10 common bugs that most of the JavaScript developer make.

1. Syntax Error

This is one of the common error which occur when we execute our program.
The Syntax error could be occur when the JavaScript statement violate the rule JavaScript syntactic rules.
It could be occur when we miss opening or close bracket.

2. Invalid Comparison Operators

Sometimes it is confusing that what equality operator use and many newbies make mistake when declaring and comparing two values.
Sometimes developers use single equality operator “=” instead of double equality operator “==” and it create ambiguous code and the output would be ambiguous too.
Because == double equality sign does comparison while single equality sign = assign value.
In some languages, it cause error while in JavaScript, the console still execute the code but the output would be buggy.

3. Wrong Use of Assignment

In JavaScript, the single equality operator assign the value to operand from the right to the left for example:

var x = 5;  

So you can see here that assignment operator assign the value of 5 to x, the common mistake newbie developer do is that they use single assignment operator when declaring If statement like below

if (x=15){.. .}

This code will not run according to our expectation if we want to compare the value of x to 15.

4. Mismatched Brackets

The syntax error appear when we miss match the curly brackets, this error mostly appear when the code gets complicated and especially when you working with complex JavaScript objects

5. Wrongly Matched Quotes

In JavaScript, you can use single, double quotation, or backticks to define string.
So when you mismatch the string like using double quoted string as a starting string and single quoted string as an ending string then you will get error.
For example:

var name = “Janie’; // You will get Error

6. Missing Semicolon

If you miss any semicolon “;” in JavaScript then you are going to get error.
This error mostly happen when you put all of your JavaScript code in single line and do not use semicolon to separate the syntax to each other.
The best way to avoid this problem is to use JavaScript code in proper way and use semicolon at the end of every statement.

7. Reference Error

The pattern and the syntax for JavaScript programming is really sophisticated.
This error occur when you try to recall some variable that you have not declared yet.
For example

var country = 'Japan';
console.log(city); // ReferenceError: city is not defined

8. Range Error

The error occur when we try to do something like recalling a value which is outside of permissible range.
This error is very common when we are writing recursion statement and want to add many function which call later to stack.
For example:

function add (a) {
    add(a - 5);

This code is going to call itself infinitely and not going to stop.


There are two kind of scope in JavaScript, function and global scope.
The variable will be global variable if you declare without using the var keyword and that variable can be used anywhere throughout your program.
But sometimes result would be detrimental and to avoid scope error always use var keyword to create new variable.

10. Extra commas

Man newbies JavaScript developer make the mistake by using the comma at the end of the last property in any JavaScript object definition.
So I result they get the error.
The last property in the JavaScript object definition should never end with comma it cause error.



Boostlog is an online community for developers
who want to share ideas and grow each other.

Delete an article

Deleted articles are gone forever. Are you sure?