Tech Study

JavaScript typeof operator | Typeof Explained

Typeof javascript

The typeof javascript operator returns a string that indicates the type of the operand’s value.

SYNTAX – typeof operand

Operand – An expression which is representing the object or primitive data whose type is to be returned.

typeof "TechStudy"                 // "string"
typeof 45                   // "number"

typeof NaN                    // "number"

typeof [1,2,3,4]              // "object"

typeof null                   // "object"

The type of method can return one of these primitive data types ( A primitive data value can  be used to refer to a single simple data value with no extra or additional properties and methods.)

  1. Number
  2. Boolean
  3. String
  4. Undefined

It can also be used to return complex data types like functions or objects. It returns “object” for objects, arrays, and null and does not return “object” for functions.

NOTE – The typeOf() operator returns objects for arrays because, in JavaScript, arrays are treated as objects.

Data Type of typeOf() ?

typeOf() is an operator in JavaScript, data types are defined for variables, but not for operators like ( +,-,*,/)

Why NULL is considered as objects?

In the first implementation of JavaScript, its values were represented as a type tag and a value. 0 was the type tag for objects and null was represented as the NULL pointer. And hence, null had 0 as the type tag, hence the typeof return value “object”.

For Example 

console.log(typeof “TechStudy”);

// Expected output: "string"

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more

Function Pointer in C++

Introduction : Function Pointer in C++ Pointers: In function pointer in c++ are the variables that consist of addresses of …

Read more