what is undefined in javascript
The undefined property indicates that a variable has not been assigned a value, A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned. what is undefined in javascript
undefined is a property of the global object. That is, it is a variable in global scope. The initial value of undefined is the primitive value undefined.
Example: undefined
var myVarA; alert(myVarA); // undefined
In the above example, we have not assigned any value to a variable named ‘myVarA’. So it is undefined.
You will get undefined value when you call a non-existent property or method of an object.
Example of Undefines in javascript :
function multiply(val1, val2, val3) { var result = val1 * val2 * val3; } var result = multiply(3, 3, 3); alert(result);// undefined
In the above example, a function Sum does not return any result but still we try to assign its resulted value to a variable. So in this case, result will be undefined.
If you pass less arguments in function call then, that parameter will have undefined value.
Example of Undefines in javascript :
function multiply(val1, val2, val3) { return val1 * val2 * val3; // val3 is undefined } Sum(3 * 3);
1 Comment