
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is typeof Operator in JavaScript?
The typeof operator is a unary operator that is placed before its single operand, which can be of any type. Its value is a string indicating the data type of the operand. The typeof operator evaluates to "number", "string" or "boolean" if its operand is a number, string, or boolean value and returns true or false based on the evaluation.
Here is a list of the return values for the typeof Operator.
Type | String Returned by typeof |
---|---|
Number | "number" |
String | "string" |
Boolean | "boolean" |
object | "object" |
Function | "function" |
Undefined | "undefined" |
Null | "object" |
Example
The following code shows how to implement typeof operator −
<html> <body> <script> var a = 10; var b = "String"; var linebreak = "<br />"; result = (typeof b == "string" ? "B is String" : "Bis Numeric"); document.write("Result => "); document.write(result); document.write(linebreak); result = (typeof a == "string" ? "A is String" : "Ais Numeric"); document.write("Result => "); document.write(result); document.write(linebreak); </script> </body> </html>
- Related Articles
- How to use typeof operator in TypeScript?
- What is typeof, GetType or is in C#?
- What is increment (++) operator in JavaScript?
- What is decrement (--) operator in JavaScript?
- What is Conditional Operator (?:) in JavaScript?
- What is Modulus Operator (%) in JavaScript?
- What is Multiplication Operator (*) in JavaScript?
- What is Addition Operator (+) in JavaScript?
- What is Assignment Operator (=) in JavaScript?
- What is Comma Operator (,) in JavaScript?
- What is spread Operator (...) in JavaScript?
- What is Subtraction Operator (-) in JavaScript?
- What is an exclamation “!” operator in JavaScript?
- What is a ternary operator (?:) in JavaScript?
- What is Logical NOT Operator (!) in JavaScript?

Advertisements