JavaScript errors

 Lesson 6: JavaScript errors

JavaScript errors are helpful messages that are displayed to programmers when they do something wrong in JavaScript.

There are many form of errors. We will learn them as we go. 

But, we will start with the most common ones.

NaN and Undefined errors.

When you first create a variable in JavaScript they have a value of undefined.

Suppose you declare a variable and forget to initialize it with a value and perform a math operation on it, the result with be a NaN(Not a Number).

Similarly if you try to concatenate a string – add two strings together when the variable isn’t initialized, the result will be undefined.

Thus, as a rule of thumb always initialize your variables with something.

This might also occur if you mix strings and numbers. Double check to see if you didn’t do something like that.

Post a Comment