JavaScript: Undefined Property

Profile picture for user arilio666

Now, what does undefined mean? The same usual pot example matches this too that the pot is only useful if it has something in it or it is just an empty vessel that has nothing to contribute to help with.

Likewise undefined property in javascript generally means that the variable declared was not assigned any values to it simply meaning that the variable container is empty.

Example #1:

var titan;
console.log(titan);

Output: undefined

As variable 'titan' is empty/not assigned any values when logged it throws undefined.

Example #2:

var titan = "eren" ;


if (typeof titan == "undefined"){
    console.log("Undefined")
}else {
    console.log("Defined")
}

Output: Defined

As the type of titan obviously came to be string it didn't go inside the if block whereas came to the else block.

Example #3:

var titan;


if (typeof titan == "undefined"){
    console.log("Undefined")
}else {
    console.log("Defined")
}

Output: Undefined

As the type of titan without any values is undefined it went into if body block and printed undefined.