> ## 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.

# TypeScript Strict Inequality

The `!==` (strict inequality) operator evaluates whether two operands are not identical. It returns `true` if the operands differ in either data type or value, and `false` if they share the exact same type and value, with the notable exception of `NaN`. Unlike the loose inequality operator (`!=`), `!==` never performs implicit type coercion during evaluation.

```typescript theme={"dark"}
operand1 !== operand2
```

## Evaluation Mechanics

At runtime, the operator follows strict equality resolution rules:

1. **Type Comparison:** If the runtime types of `operand1` and `operand2` differ, it immediately evaluates to `true`.
2. **Value Comparison:** If the types are identical, it compares the underlying values. If the values differ, it evaluates to `true`.
3. **The `NaN` Exception:** In JavaScript and TypeScript, `NaN` (Not-a-Number) is of type `number` but is strictly unequal to itself. Therefore, `NaN !== NaN` evaluates to `true`. To accurately check if a value is `NaN`, you must use `Number.isNaN()` rather than the `!==` operator.
4. **Reference Types:** For objects, arrays, and functions, `!==` evaluates memory identity (reference equality) rather than structural equivalence. Two distinct objects with identical properties will evaluate to `true` because they occupy different memory addresses.

## TypeScript Compiler Behavior

While the runtime behavior is identical to JavaScript, TypeScript applies static type analysis to the `!==` operator at compile time.

If the TypeScript compiler determines that the types of the two operands have no intersection (i.e., they are mutually exclusive or non-overlapping), it will throw a `ts(2367)` compiler error. TypeScript flags this because comparing two completely unrelated types with `!==` will always evaluate to `true`, indicating a logical flaw in the code.

```typescript theme={"dark"}
let str: string = "10";
let num: number = 10;

// Compiler Error ts(2367): This condition will always return 'true' 
// since the types 'string' and 'number' have no overlap.
const isDifferent = str !== num; 
```

If types already overlap (such as a union type intersecting with a primitive), the compiler naturally allows the check. However, to perform a strict inequality check across *unrelated* or *non-overlapping* types, you must bypass the compiler by casting one or both operands to a top type like `any` or `unknown`.

```typescript theme={"dark"}
let str: string = "10";
let num: number = 10;

// Bypassing the compiler check for non-overlapping types using 'unknown'
const isForcedDifferent = (str as unknown) !== num; 

let val1: string | number = "10";
let val2: number = 10;

// Valid compilation: 'val1' could potentially be a number, 
// so the types naturally overlap. Evaluates to true at runtime.
const isDifferent = val1 !== val2; 
```

## Reference Evaluation Example

When evaluating reference types, the compiler allows the comparison as long as the types overlap, but the runtime evaluation strictly checks the memory pointer.

```typescript theme={"dark"}
const objA: { id: number } = { id: 1 };
const objB: { id: number } = { id: 1 };
const objC = objA;

const check1 = objA !== objB; // Valid compilation. Evaluates to true (different references).
const check2 = objA !== objC; // Valid compilation. Evaluates to false (same reference).
```

<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 TypeScript 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>
