According to ECMAScript standard Javascript has seven data types. Six data types that are primitives and one is non primitive
This are the primitive datatype
- Boolean. true and false.
- null. A special keyword denoting a null value. Because JavaScript is case-sensitive, null is not the same as Null, NULL, or any other variant.
- undefined. A top-level property whose value is undefined.
- Number. 42 or 3.14159.
- String. “Howdy”
- Symbol (new in ECMAScript 2015). A data type whose instances are unique and immutable.
And non primitive is Object
The
undefined
value behaves asfalse
when used in a Boolean context but in numeric context it behave like NaN
var myVal; console.log(typeof myVal);//"undefined" // In boolean context if(!myVal) console.log("I am undefined");//"I am undefined" // In numeric context console.log(myVal * 4);//NaN