---
title: What Is the JavaScript TypeOf Function? How Does It Work? · PrepScholar
description: Confused by the JavaScript typeof operator? Learn what it is, how it works, and when to use it with our complete JS typeof guide.
image: https://360031.fs1.hubspotusercontent-na1.net/hubfs/360031/feature-computer-code-matrix.jpg
---

**[![PrepScholar](https://www.prepscholar.com/wp-content/uploads/2023/03/PrepScholar-Logo-Colored.png)](https://www.prepscholar.com/)**

CALL NOW:

[+1 (866) 811-5546](tel:18668115546)

[![Start Free Trial](https://no-cache.hubspot.com/cta/default/360031/interactive-171805697634.png)](https://cta-service-cms2.hubspot.com/web-interactives/public/v1/track/redirect?encryptedPayload=AVxigLKJluK2NyG3jpAJh%2F2lClc1fhnVHyMZoQonqRxtJngB8FMX6lc78F84JqOaVAL0d36TA5%2FYuH%2FLCJw8AG3ewREi%2F7a3XDouZgjxWfYCBUge6z76KnSykOxONl3avMK0gUjJGpJdyJE2BDTx8g3bsgHwMtx4Kr9Jfh6Jr7WA2XEIgtLw1OoVvAMo4Kw%3D&webInteractiveContentId=171805697634&portalId=360031)

## Choose Your Test

SAT Prep ACT Prep

[PrepScholar Advice Blog](https://blog.prepscholar.com/)

 ☰

- Search Blogs By Category
- [SAT](https://blog.prepscholar.com/topic/sat)
- [ACT](https://blog.prepscholar.com/topic/act)
- [College Admissions](https://blog.prepscholar.com/topic/college-admissions)
- [AP and IB Exams](https://blog.prepscholar.com/topic/advanced-placement-ap)
- [PSAT](https://blog.prepscholar.com/topic/psat-info-and-strategies)
- [TOEFL](https://blog.prepscholar.com/topic/toefl)
- [GPA and Coursework](https://blog.prepscholar.com/topic/coursework-gpa)

# [What Is the JavaScript TypeOf Function? How Does It Work?](https://blog.prepscholar.com/javascript-typeof)

![author image](https://cdn2.hubspot.net/hubfs/360031/author_ashley.png)

Posted by [Ashley Robinson](https://blog.prepscholar.com/author/ashley-robinson) | Updated on August 19, 2024

[General Education](https://blog.prepscholar.com/topic/general-education)

 

![feature-computer-code-matrix](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/feature-computer-code-matrix.jpg?width=500&name=feature-computer-code-matrix.jpg)

We’ve all stumbled on a web page that just doesn’t work. You know the type: the links aren’t clickable, the scrolling is all over the place, and sometimes...they automatically play music. (*The worst.*)

When a website misbehaves, bad JavaScript is usually at fault. That’s because JavaScript is the scripting language that controls the interactive elements of a website. In fact, JavaScript is actually a robust, powerful scripting language that automates processes like animating images or providing autofill suggestions. **Basically, JavaScript is one of the fundamental coding languages of the web.**

Like any language, there’s lots you can do with JavaScript. **But today, we’re going talk about one specific type of JavaScript command: the TypeOf function.** In this article, you’ll learn about the JavaScript TypeOf function, including what it is, how it works, and its most common uses.

So let’s dive in!

**![body-JavaScript-Logo](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/body-JavaScript-Logo.jpg?width=350&name=body-JavaScript-Logo.jpg)**

 

## **What Is a JavaScript Data Type?**

Before we start talking about the JavaScript TypeOf function, we first have to talk about JavaScript data types. [**A data type is a classification given to different kinds of data used in programming.**](https://www.codecademy.com/courses/introduction-to-javascript/lessons/introduction-to-javascript/exercises/types?action=resume_content_item) There are [seven data types](https://javascript.info/types) that can be used in JavaScript, and we’ve broken them down in the table below:

 

| **Data Type** | **Use** |
| --- | --- |
| Number | Deals with any number, including decimals. You can also do operations (like multiplication, division, etc.) with this data type. |
| String | A string of characters surrounded by single or double quotes. |
| Boolean | Sets a true/false (or yes/no) value. |
| Null | Indicates the intentional absence of a value. Basically means “nothing,” “empty,” or “value unknown.”   |
| Undefined | Also indicates the absence of a value. Unlike “null,” “undefined” is usually used when a variable is declared but a value is unassigned. |
| Symbols | Unique identifiers for objects. |
| Object | Collections of related data. Unlike other data types, which can only contain a single thing, objects store collections of data. |

   

 

 

**![body-red-pencil-important](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/body-red-pencil-important.jpg?width=600&name=body-red-pencil-important.jpg)**

 

## **Why Are Data Types Important?**

In JavaScript,[**a data type is basically a category of data that can be stored and/or manipulated within a program**](https://www.tutorialrepublic.com/javascript-tutorial/javascript-data-types.php)**.** Depending on the type of data you’re using, JavaScript will treat the data differently. So for example, JavaScript deals with an undefined data set much differently than it deals with an object!

**The other reason data types are important is because they dictate what you can do with the data you provide—and whether that data will work or not.** For example, if you try to assign a value to a “null” data type, it won’t work because null indicates an empty value! Likewise, there are some data types that only do one thing, like the boolean data type, while others can work with collections of data.

**In other words, data types are one of the fundamental building blocks of JavaScript.**

 

**![body-woman-question-marks](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/body-woman-question-marks.jpg?width=450&name=body-woman-question-marks.jpg)**

 

## **What Is the Javascript TypeOf Function?**

Now that you know what data types are, the typeof function will make more sense: that’s because **the JavaScript TypeOf command is used to check the data type of a particular** [**operand**](https://www.dummies.com/web-design-development/javascript/javascript-operands/)**, which is a JavaScript array, data type, or object.**

In order to use the TypeOf command, [you would write it like you would any operation that uses a single value](https://blog.logrocket.com/javascript-typeof-2511d53a1a62) (also known as a [unary operator](https://scotch.io/tutorials/javascript-unary-operators-simple-and-useful)). That means the script would look like this:

typeof x

You can also use the TypeOf operator like you would a JavaScript function. [The syntax would look something like this](https://blog.logrocket.com/javascript-typeof-2511d53a1a62):  

typeof(x)

**Using the JavaScript TypeOf function is particularly useful for checking the value of** [**JavaScript expressions**](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Expressions_and_Operators)**!**

 

## **How Do You Use the Javascript TypeOf Function?**

**When you use the JavaScript TypeOf function to check the data type of an operand, it returns a** [**string**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**, or text, that contains the data type!** Here’s an example of how you might check to see if an object is undefined:

If (typeof object === ‘undefined’)

The TypeOf function is an important tool when dealing with complex code. It allows a programmer to quickly check a variable’s data type—or whether it’s “undefined” or “null”—without going through the code line by line! Additionally, the TypeOf function can also check whether an operand is an object or not.

Depending on the output of the TypeOf function, a programmer can adjust their previous code or quickly pick up where they left off on a project. In other words, **the TypeOf function is a quick way to check data to make sure that a script will work.**

 

## **What Are the Possible Outputs of the TypeOf Function?**

Because the JavaScript TypeOf function is used to check data types, t**he possible outputs of the TypeOf operator are all data types, too**. [Here’s a quick summary](https://blog.logrocket.com/javascript-typeof-2511d53a1a62) of the different type of outputs you might see:

  

| **Value** | **TypeOf** |
| --- | --- |
| undefined | “undefined” |
| null | “object” |
| Boolean (true or false) | “boolean” |
| all numbers | “number” |
| all strings | “string” |
| all symbols | “symbol” |
| all functions | “function” |
| all arrays | “object” |
| native objects | “object” |
| host objects | Dependent on implementation |
| other objects | “object” |

 

**![body-whats-next](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/body-whats-next.jpg?width=485&name=body-whats-next.jpg)**

 

 

## **What’s Next?**

**If you’re interested in coding, it might be worth considering a computer science major.** But how do you know if computer science is *really* right for you? [Here are five key factors to consider when choosing your major.](https://blog.prepscholar.com/how-to-choose-a-major)

If you do want to go into computer science, it’s important to get into a good college. **One of the best ways to do that is to make sure you’re taking the right courses in high school.** [Check out this expert guide to the classes you should—and shouldn’t—take before you start your college applications.](https://blog.prepscholar.com/what-classes-should-you-take-in-high-school)

You might have heard that AP classes look good on your college application. **If you’re not sure what AP classes are or how they affect your college admissions chances,** [take a look at this AP overview.](https://blog.prepscholar.com/are-ap-classes-worth-it-benefits)

### Trending Now

[How to Get Into Harvard and the Ivy League](https://blog.prepscholar.com/how-to-get-into-harvard-and-the-ivy-league-by-a-harvard-alum)

[How to Get a Perfect 4.0 GPA](https://blog.prepscholar.com/how-to-get-a-4-0-gpa-and-get-better-grades-by-a-harvard-alum)

[How to Write an Amazing College Essay](https://blog.prepscholar.com/how-to-write-a-college-essay)

[Should You Take the SAT or ACT?](https://quiz.prepscholar.com/sat-vs-act)

[What Exactly Are Colleges Looking For?](https://blog.prepscholar.com/what-do-colleges-look-for)

[ACT vs. SAT: 10 Key Differences](https://blog.prepscholar.com/act-vs-sat)

[Calculate Your College Chances](https://mycollegechances.prepscholar.com/)

Get Your Free

**[![PrepScholar](https://www.prepscholar.com/wp-content/uploads/2023/03/PrepScholar-Logo-Colored.png)](https://www.prepscholar.com/)**

eBook

[5 Tips to Raise Your SAT Score 160+ Points](https://www.prepscholar.com/rp/sat-5-tips-ebook/)

[5 Tips to Raise Your ACT Score 4+ Points](https://www.prepscholar.com/rp/act-5-tips-ebook/)

### SAT Prep

[Find Your Target SAT Score](https://blog.prepscholar.com/what-is-a-good-sat-score-a-bad-sat-score-an-excellent-sat-score)

[Free Complete Official SAT Practice Tests](https://blog.prepscholar.com/complete-official-sat-practice-tests-free-links)

### **[How to Get a Perfect SAT Score, by an Expert Full Scorer](https://blog.prepscholar.com/how-to-get-a-perfect-sat-score-by-a-2400-sat-scorer)**

[Score 800 on SAT Math](https://blog.prepscholar.com/how-to-get-800-on-sat-math-by-a-perfect-scorer)

[Score 800 on SAT Reading and Writing](https://blog.prepscholar.com/how-to-get-800-on-sat-reading-and-writing)

[Raise Your SAT Score by 160+ Points GUARANTEED. Start Your 5-Day Risk-Free Trial](https://www.prepscholar.com/sat-test-prep/?utm_source=databasepage&utm_medium=sidebar&utm_campaign=sat_guarantee)

### ACT Prep

[Find Your Target ACT Score](https://blog.prepscholar.com/what-is-a-good-act-score-a-bad-act-score-an-excellent-act-score)

[Complete Official Free ACT Practice Tests](https://blog.prepscholar.com/complete-official-act-practice-tests-free-links)

### **[How to Get a Perfect ACT Score, by a 36 Full Scorer](https://blog.prepscholar.com/how-to-get-a-perfect-act-score-by-a-36-full-scorer)**

[Get a 36 on ACT English](https://blog.prepscholar.com/how-to-get-36-on-act-english-9-strategies-from-a-perfect-scorer)

[Get a 36 on ACT Math](https://blog.prepscholar.com/how-to-get-36-on-act-math-8-strategies-by-a-perfect-scorer)

[Get a 36 on ACT Reading](https://blog.prepscholar.com/how-to-get-36-on-act-reading-11-strategies-from-a-perfect-scorer)

Stay Informed

Get the latest articles and test prep tips!

- [![Follow us on Facebook (icon)](https://360031.fs1.hubspotusercontent-na1.net/hubfs/360031/facebook_logo.png)](https://www.facebook.com/prepscholar)
- [![Follow us on X (icon)](https://360031.fs1.hubspotusercontent-na1.net/hubfs/360031/twitterx-50.png)](https://twitter.com/intent/follow?region=follow_link&screen_name=PrepScholar&tw_p=followbutton)
- [![Follow us on Instagram (icon)](https://360031.fs1.hubspotusercontent-na1.net/hubfs/360031/instagram-sidebar.webp)](https://www.instagram.com/prepscholar/)

 Get Exclusive Tips for College Admissions

 Sign up to receive free guidance on everything from acing the SAT to writing a standout college admissions essay.

×

## Thanks for Subscribing!

![Check icon](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/file-2386656898.png/subscribe_check.png.png?width=175&name=subscribe_check.png)

 To receive immediate updates on all our helpful guides and strategies, **follow us** on social media: [![Facebook](https://blogprepschola.wpenginepowered.com/wp-content/uploads/2025/03/26de6c2beb2b71ee5b8d660200359259.png)](https://www.facebook.com/prepscholar) [![X](https://blogprepschola.wpenginepowered.com/wp-content/uploads/2025/03/f233666501ea25d3fcf3c390d2f08c7b.png)](https://x.com/intent/follow?region=follow_link&screen_name=PrepScholar&tw_p=followbutton) [![LinkedIn](https://blogprepschola.wpenginepowered.com/wp-content/uploads/2025/03/linkedin.png)](https://www.linkedin.com/company/prepscholar/) [![Instagram](https://blogprepschola.wpenginepowered.com/wp-content/uploads/2025/03/download-1.png)](https://www.instagram.com/prepscholar/)

**Have friends who also need help with test prep?** Share this article!

[![Share on email](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/email-color.png?width=24&name=email-color.png)](mailto:?subject=Check%20out%20https%3A%2F%2Fblog.prepscholar.com%2Fjavascript-typeof%3Futm_medium%3Dsocial%26utm_source%3Demail%20&body=Check%20out%20https%3A%2F%2Fblog.prepscholar.com%2Fjavascript-typeof%3Futm_medium%3Dsocial%26utm_source%3Demail) [![Share on facebook](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/facebook-color.png?width=24&name=facebook-color.png)](http://www.facebook.com/share.php?u=https%3A%2F%2Fblog.prepscholar.com%2Fjavascript-typeof%3Futm_medium%3Dsocial%26utm_source%3Dfacebook) [![Share on twitter](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/x-twitter-color.png?width=24&name=x-twitter-color.png)](https://twitter.com/intent/tweet?original_referer=https%3A%2F%2Fblog.prepscholar.com%2Fjavascript-typeof%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&url=https%3A%2F%2Fblog.prepscholar.com%2Fjavascript-typeof%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&source=tweetbutton&text=) [![Share on linkedin](https://360031.fs1.hubspotusercontent-na1.net/hub/360031/hubfs/linkedin-color.png?width=24&name=linkedin-color.png)](http://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fblog.prepscholar.com%2Fjavascript-typeof%3Futm_medium%3Dsocial%26utm_source%3Dlinkedin)

 About the Author

![author image](https://cdn2.hubspot.net/hubfs/360031/author_ashley.png)

 Ashley Robinson

 Ashley Sufflé Robinson has a Ph.D. in 19th Century English Literature. As a content writer for PrepScholar, Ashley is passionate about giving college-bound students the in-depth information they need to get into the school of their dreams.

## Ask a Question Below

Have any questions about this article or other topics? Ask below and we'll reply!

**[![PrepScholar](https://www.prepscholar.com/wp-content/uploads/2023/03/PrepScholar-Logo-White.png)](https://www.prepscholar.com)**

- [WHO WE ARE](https://www.prepscholar.com/who-we-are/)
- [SUCCESS STORIES](https://www.prepscholar.com/case-studies/)
- [ADVICE BLOG](https://blog.prepscholar.com/)
- [FOR SCHOOLS](https://www.prepscholar.com/for-schools/)

- [SAT](https://www.prepscholar.com/sat-test-prep/)
- [ACT](https://www.prepscholar.com/act-test-prep/)
- [PSAT](https://www.prepscholar.com/psat-test-prep/)
- [AP](https://www.prepscholar.com/ap-tutoring/)
- [GRE](https://www.prepscholar.com/gre-test-prep/)
- [GMAT](https://www.prepscholar.com/gmat-test-prep/)
- [TOEFL](https://www.prepscholar.com/toefl-test-prep/)
- [ADMISSIONS](https://www.prepscholar.com/college-admissions-consulting/)

- [TERMS OF SERVICE](https://www.prepscholar.com/terms-of-service/)
- [PRIVACY POLICY](https://www.prepscholar.com/privacy-policy/)

- [![follow us on X (icon)](https://cdn2.hubspot.net/hubfs/360031/twitter-64.png)](https://twitter.com/intent/follow?region=follow_link&screen_name=PrepScholar&tw_p=followbutton)
- [![Follow us on Facebook (icon)](https://cdn2.hubspot.net/hubfs/360031/facebook-64.png)](https://www.facebook.com/prepscholar)
- [![follow us on Instagram (icon)](https://360031.fs1.hubspotusercontent-na1.net/hubfs/360031/instagram-64.svg)](https://www.instagram.com/prepscholar/)
- [![follow us on TikTok (icon)](https://360031.fs1.hubspotusercontent-na1.net/hubfs/360031/tiktok-50.svg)](https://www.tiktok.com/@prepscholarofficial)
- [![Follow us on LinkedIn (icon)](https://360031.fs1.hubspotusercontent-na1.net/hubfs/360031/linkedin50.png)](https://www.linkedin.com/company/prepscholar/)

© PrepScholar 2013-2025. All rights reserved

 SAT® is a registered trademark of the College Entrance Examination BoardTM. The College Entrance Examination BoardTM does not endorse, nor is it affiliated in any way with the owner or any content of this web site.   
 ACT® is a registered trademark belonging to ACT Education Corporation ("ACT"). ACT is not involved with or affiliated with PrepScholar Inc., nor does ACT endorse or sponsor any of the products or services offered by PrepScholar Inc.   
 GRE® and TOEFL® are registered trademarks of the ETS®. The ETS® does not endorse, nor is it affiliated in any way with, the owner or any content of this web site.   
 GMAT® is a registered trademark of the Graduate Management Admissions Council®. The Graduate Management Admissions Council® does not endorse, nor is it affiliated in any way with, the owner or any content of this website.

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Ashley Robinson",
    "url" : "https://blog.prepscholar.com/author/ashley-robinson"
  },
  "dateModified" : "2024-08-19T18:56:18+00:00",
  "datePublished" : "2019-05-08T22:00:00+00:00",
  "description" : "Confused by the JavaScript typeof operator? Learn what it is, how it works, and when to use it with our complete JS typeof guide.",
  "headline" : "What Is the JavaScript TypeOf Function? How Does It Work?",
  "image" : "https://cdn2.hubspot.net/hubfs/360031/feature-computer-code-matrix.jpg",
  "mainEntityOfPage" : {
    "@id" : "https://blog.prepscholar.com/javascript-typeof",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://www.prepscholar.com/wp-content/uploads/2023/03/PrepScholar-Logo-Colored.png"
    },
    "name" : "PrepScholar"
  }
}
```