Login
Your Email
Pasword
Home
Write
Trending
History
Liked
Dashboard

How to avoid Common beginner's mistakes in JavaScript?

There are some common everyday problems that you need to fix in order to get your JavaScript code to run correctly.

Do you have similar website/ Product?
Show in this page just for only $2 (for a month)
Create an Ad
0/60
0/180
Sometimes your code is not running successfully it gives error but there is not a big mistake you just need to check few things you missed or misplaced:
1.If your code is not working and error show that something is undefined then do check that you have spelt all your variable names, function names correctly.Sometimes this little mistake can create trouble.
Follow the right script if Language is case sensitive.
 E.g : 
"getElementsByTagName()" is Right"getElementbyTagName()" is wrong.
"getElementsByName()" is Right"getElementByName()" is wrong.
2.Try to make sure you don't place any semi-colons incorrectly. 
 E.g: 
elem.style.color = 'red'; is Rightelem.style.color = 'red;' is Wrong
3.There are different things that can be wrong with functions. One of the most common error is in declaration the function, not call it anywhere.
E.g:
function myFunction()
 {
 alert('This is my function.');
 };
This code will not work unless you call it like with 
myFunction();

4.Functions have their own scope and you can't access a variable value set inside a function from outside the function, unless you declared the variable globally or return the value out of the function. 
5.When you return a value out of a function then the JavaScript interpreter exits the function no code declared after the return statement will run.
Some browsers e.g Firefox will give an error message in the developer console if you have code after a return statement. 
6.When you assign something normally in JavaScript then use a single equals sign.
E.g:
var myNumber = 0;
It doesn't work in Objects and with objects you need to separate member names from their values using colons, and separate each member with a comma.
E.g:
var myObject = {
 name : 'Chris',
 age : 38
 }
CONTINUE READING
beginner's mistakes
JavaScript
JavaScript common problems
Ayesha
Tech writer at newsandstory