Primitive types:

  • string
  • number
  • boolean
  • null
  • undefined

Complex types:

  • function
  • object

In JavaScript arrays are objects.

undefined

In JavaScript, a variable without a value, has the value undefined. The typeof is also undefined.

var person; // Value is undefined, type is undefined

null

In JavaScript null is “nothing”. It is supposed to be something that doesn’t exist.

Unfortunately, in JavaScript, the data type of null is an object.

You can consider it a bug in JavaScript that typeof null is an object. It should be null.

var person = null;  // Value is null, but type is still an object

Difference Between Undefined and Null

typeof undefined           // undefined
typeof null                // object
null === undefined         // false
null == undefined          // true

JavaScript evaluates expressions from left to right. Different sequences can produce different results:

var x = 16 + 4 + "Volvo"; // 20Volvo
var y = "Volvo" + 16 + 4; // Volvo164

JavaScript has dynamic types. This means that the same variable can be used to hold different data types:

var x;            // Now x is undefined
var x = 5;        // Now x is a Number
var x = "John";   // Now x is a String

Yonggoo Noh

I am interested in Computer science and Mathematics.