Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

All Together

typeof “John”          // Returns “string”
typeof (“John”+“Doe”)  // Returns “string”
typeof 3.14            // Returns “number”
typeof (33 + 66)       // Returns “number”
typeof NaN             // Returns “number”
typeof 1234n           // Returns “bigint”
typeof true            // Returns “boolean”
typeof false           // Returns “boolean”
typeof {name:‘John’}   // Returns “object”
typeof [1,2,3,4]       // Returns “object”
typeof {}              // Returns “object”
typeof []              // Returns “object”
typeof new Object()    // Returns “object”
typeof new Array()     // Returns “object”
typeof new Date()      // Returns “object”
typeof new Set()       // Returns “object”
typeof new Map()       // Returns “object”
typeof function () {}  // Returns “function”
typeof x               // Returns “undefined”
typeof null            // Returns “object”

Note: The data type of NaN (Not a Number) is still considered a number.

The void Operator

The void operator evaluates an expression and returns undefined. It’s commonly used to obtain the undefined primitive value with void(0), which is useful for evaluating an expression without utilizing its return value.

Example

<a href=”javascript:void(0);”>
  Useless link
</a>

<a href=”javascript:void(document.body.style.backgroundColor=’red’);”>
  Click me to change the background color of body to red
</a>