-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
typeof
– Checking Data Types in JavaScriptThe typeof
operator is used in JavaScript to determine the data type of a variable or value. It is useful for debugging and validation.
typeof operand
You can use typeof
with variables, literals, or expressions.
typeof "Hello"; // "string"
typeof 42; // "number"
typeof true; // "boolean"
let name = "Alice";
console.log(typeof name); // "string"
let age = 25;
console.log(typeof age); // "number"
typeof
Value or Variable | typeof result |
---|---|
"Hello" |
"string" |
42 , 3.14 |
"number" |
true , false |
"boolean" |
undefined |
"undefined" |
null |
"object" (✅ JavaScript bug) |
[1, 2, 3] |
"object" |
{a: 1} |
"object" |
function() {} |
"function" |
123n (BigInt) |
"bigint" |
Symbol("id") |
"symbol" |
null
let data = null;
console.log(typeof data); // "object" ✅ (this is a well-known JavaScript quirk)
typeof
returns a string with the type
instanceof
checks whether an object is an instance of a specific constructor
Q1. How do you check the data type of the string "Welcome"
using the typeof
operator?
Q2. How do you find the type of a variable isOnline = true
?
Q3. What will typeof 100
return, and how do you use it in a console log statement?
Q4. How do you check the type of an undefined variable let result;
using typeof
?
Q5. What does typeof null
return, and why is it considered a JavaScript bug?
Q6. How do you use typeof
to check if a function myFunc
is of type "function"
?
Q7. How do you determine if an array let colors = ["red", "blue"]
is an object using typeof
?
Q8. How do you use typeof
to check the type of a BigInt value 123456789n
?
Q9. How do you store the result of typeof
in a variable and print it?
Q10. How do you check the type of a symbol declared as let sym = Symbol("key")
?
Q1: What does typeof "JavaScript" return?
Q2: What is the output of typeof 10?
Q3: What will typeof null return?
Q4: Which data type returns "function" when used with typeof?
Q5: Which of the following is NOT a correct use of typeof?
Q6: What is the type of true in JavaScript?
Q7: Which keyword is used to define a variable whose type will be checked using typeof?
Q8: What does typeof undefined return?
Q9: Which of the following statements is true?
Q10: What will typeof {name: "Alex"} return?