Open In App

What is typeof Operator in JavaScript ?

The typeof operator in JavaScript is used to check the type of the operand passed to it. It will return the type of the passed operand that can be used to compare the types of the two different variables declared in the code. The typeof operator is used by specifying it just before the name of the operand to get its type. It returns the type of the operand in the form of a string. So, if you are trying to compare the type manually by specifying it, you should use the string format to specify it.

Example: The below code explains the use of the typeof operator to check the types of the different variables.




const name = "GeeksforGeeks";
const desc = "A Computer Science Portal."
 
if(typeof name === typeof desc){
    console.log("Company Name: ", name,
        ", Description: ", desc);
}

Output
Company Name:  GeeksforGeeks , Description:  A Computer Science Portal.
Article Tags :