Defaultjsdatatypes.md - brainchildservices/curriculum GitHub Wiki

Slide 1

Default Value

The undefined data type represents value that is not assigned. If a variable is declared but the value is not assigned, then the value of that variable will be undefined. An undefined value is very similar to null value as it also makes a type of its own. The meaning of undefined is “value is not assigned”. For example,

 let name;
 document.write("Name is " + name); //age is a undefined

It is also possible to explicitly assign a variable value undefined. For example,

 let name = undefined;
 document.write("Name is " + name); //age is a undefined

Note: It is recommended not to explicitly assign undefined to a variable. Usually, null is used to assign 'unknown' or 'empty' value to a variable.

Wrong Syntax Example

 var age = 30; //we assigned a value
 document.write("age is " + age);
 //Output:- age is 30 ,not a undefined value as it is assigned