Top 5 Mistakes every beginner make while learning JavaScript

 

 

· web design course,javascript

For every beginner who has just started learning JS, it is obvious to make mistakes but the most important thing is not to repeat them. In this guide, we have mentioned the top 5 very beginner level mistakes that you should avoid. If you are in a JavaScript course and just have started learning it, then this blog is an ideal one to read.

5 main mistakes to avoid as a JavaScript course student

Mistake 1. Not returning from a function

Whenever you call a function and in exchange you receive undefined. We’ve seen this error many times in the expedition of javascript. Now the million dollar question is why it happens because, javascript function return undefined value by default so if we don’t return something explicitly with return keyword it will show the result of undefined.

For example:

const addValue = (a, b) => {

a + b;

};

console.log(addValue(2,3)); // undefined

So instead of doing this return the actual result.

const addValue = (a, b) => {

return a + b;

};

console.log(addValue(2,3)); // 5

Mistake 2. Incomplete knowledge of variable scope:

In javacsript, there is a very common problem that new developers use to face and that is not a complete knowlwdge of variable scope and it is also quite difficult topic to graps. That appears to be a fairly common issue. But first, consider a more javascript-specific example. This is related to the use of const and let vs var. we know that var is an older way of declaring variables, but it is still used in source code and documentation.

Let’s try to understand this with an example we’ll declare a variable with var keyword inside a loop and check that is it accessible outside the loop or not.

for (let i = 0; i < 10; i++) {

var num = 5;

}

console.log(num); // 5

And now if we implement same code with let keyword it won’t be able to accessible outside the loop.

for (let i = 0; i < 10; i++) {

let num = 5;

}

console.log(num); // ReferenceError: num is not defined

Mistake 3. Nested looping:

Composition of loop is called nested loop, a loop is used to perform repetitive block of code as many times.

A loop within a loop takes time to run and this time will keep growing if we run lot of other things on it. So it is bad because it gets slow.

If we want to create a two or three dimesional array in javascript it will use more resources and the code process will be lenghty.

For example

var digits = [

[5, 2, 3, 4],

[7, 2, 4, 4],

];

let total = 0;

for (var i = 0; i < digits.length; i++) {

for (var j = 0; j < digits[i].length; j++) {

total += (digits[i][j]);

}

}

console.log(total); // 31

To avoid this we have a solution called recursion.

Mistake 4. Double vs Triple equal:

This is a major source of misunderstanding in javascript. To begin, it’s important to understand that double equals function is helpful in comparing two values without regard for their data types.and the triple equals function, on the other hand, compares two values while taking their data types into account.

For example 

let a = 3;

let b = "3"; 

console.log(a == b); // true;

According to double equal sign the answer is true but if we use triple equal sign the same code will give answer false.

let a = 3; 

let b = "3";

console.log(a === b); // false

If it seems a kind of tough to understand for you, then don’t worry, you can first start from the basics by joining web development course in Delhi which covers JS training for beginners.

Mistake 5. Reassignment of const variable:

In javascript we’ve learned about three variable var, let and const but these variables contain different properties where we can redeclare same variable name with var but in case of const we can’t do this because when we’ll try to do this with const it will through an error.

For example:

const counting = 0;

for (let i = 0; i < 10; i++) {

counting = counting + i;

}

console.log(counting); // invalid assignment to const 'counting'

So, these were the main mistakes to skip while learning the JS under any web design course in Delhi. Now you haven’t joined any course yet then it’s the right time to pick up the best one from the list of web design courses in Delhi at ADMEC Multimedia Institute.

ADMEC is known as the best web design and development institute in Delhi and offers career-oriented training programs for beginners to make them efficient in programming. It has both web design and web development courses that are planned as per the industry standard and delivered by the expert professionals.