Open In App

What is typeof Operator in JavaScript ?

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Javascript




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.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads