> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript Typeof

The `typeof` operator is a unary operator that evaluates its operand and returns a string value representing the underlying JavaScript data type of that operand.

## Syntax

The operator can be applied with or without grouping parentheses. The parentheses act as standard mathematical grouping operators, not as function invocation.

```javascript theme={"dark"}
typeof operand
typeof (operand)
```

## Return Values

The ECMAScript specification restricts the `typeof` operator to returning one of eight specific string values.

| Operand Type                     | Return Value  |
| :------------------------------- | :------------ |
| Undefined                        | `"undefined"` |
| Null                             | `"object"`    |
| Boolean                          | `"boolean"`   |
| Number                           | `"number"`    |
| BigInt                           | `"bigint"`    |
| String                           | `"string"`    |
| Symbol                           | `"symbol"`    |
| Function (implements `[[Call]]`) | `"function"`  |
| Any other Object                 | `"object"`    |

## Syntax Visualization

```javascript theme={"dark"}
// Primitives
typeof undefined;           // "undefined"
typeof true;                // "boolean"
typeof 42;                  // "number"
typeof 10n;                 // "bigint"
typeof "ECMAScript";        // "string"
typeof Symbol("ref");       // "symbol"

// Objects
typeof { key: "value" };    // "object"
typeof [1, 2, 3];           // "object"
typeof new Date();          // "object"
typeof new String("text");  // "object" (Wrapper object, not primitive)

// Functions
typeof function() {};       // "function"
typeof class C {};          // "function"
typeof Math.sin;            // "function"
```

## Technical Quirks and Edge Cases

**The `null` Bug**

```javascript theme={"dark"}
typeof null; // "object"
```

This is a recognized historical artifact in JavaScript. In the first implementation of JS, values were represented as a type tag and a value. The type tag for objects was `0`. `null` was represented as the NULL pointer (which is `0x00` on most platforms). Consequently, `null` had an object type tag, causing `typeof` to return `"object"`. This behavior is permanently retained in the ECMAScript specification for backward compatibility.

**Not-A-Number (`NaN`)**

```javascript theme={"dark"}
typeof NaN; // "number"
```

Despite its name, `NaN` is a numeric data type defined by the IEEE 754 floating-point standard. Therefore, the engine evaluates it as a number.

**Undeclared Variables vs. Temporal Dead Zone (TDZ)**
Applying `typeof` to an undeclared variable is the only way to safely read or evaluate it without throwing a `ReferenceError`. It safely returns `"undefined"`.

```javascript theme={"dark"}
typeof undeclaredVariable; // "undefined"
```

However, this safety mechanism does not apply to variables declared with `let` or `const` that are currently in the Temporal Dead Zone (TDZ). Attempting to evaluate them before initialization will throw an error.

```javascript theme={"dark"}
typeof blockScopedVar; // ReferenceError: Cannot access 'blockScopedVar' before initialization
let blockScopedVar = 10;
```

**Document.all**

```javascript theme={"dark"}
typeof document.all; // "undefined"
```

`document.all` is a host object that implements a special `[[IsHTMLDDA]]` internal slot. The ECMAScript specification explicitly dictates that `typeof` must return `"undefined"` for objects implementing this slot, primarily to support legacy browser detection code.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor JavaScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
