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

The increment operator (`++`) is a unary mutator operator that adds one (1) to its operand and evaluates to a numeric value. It requires an l-value (such as a variable, array element, or object property) as its operand. If the operand is not already a numeric type, the operator applies the internal `ToNumeric` abstract operation to coerce it into a `Number` or `BigInt` before performing the addition.

The operator has two distinct syntactic forms that dictate the order of evaluation and mutation: postfix and prefix.

```javascript theme={"dark"}
// Postfix syntax
operand++

// Prefix syntax
++operand
```

## Postfix Increment (`x++`)

In the postfix position, the operator evaluates and returns the *current* value of the operand before the increment operation occurs. The mutation happens in memory, but the expression itself resolves to the unmutated value.

```javascript theme={"dark"}
let x = 10;
let y = x++; 

console.log(y); // 10 (Value returned before increment)
console.log(x); // 11 (Variable mutated in memory)
```

## Prefix Increment (`++x`)

In the prefix position, the operator increments the operand in memory first, and then the expression evaluates to the *newly incremented* value.

```javascript theme={"dark"}
let a = 10;
let b = ++a; 

console.log(b); // 11 (Value returned after increment)
console.log(a); // 11 (Variable mutated in memory)
```

## Implicit Type Coercion and `ToNumeric`

Unlike the binary addition operator (`+`), which can perform string concatenation, the `++` operator strictly performs mathematical addition. By applying the `ToNumeric` abstract operation, the operator handles different data types as follows:

* **BigInt:** If the operand is a `BigInt`, it is incremented by `1n`. It is *not* coerced to a `Number`, and its type remains `"bigint"`.
* **Valid Coercible Types:** If the operand is a numeric String, Boolean, or Null, it is coerced into a `Number` and incremented by `1`. Because JavaScript variables are dynamically typed, this simply reassigns the variable to a new value of type `Number`.
* **Invalid Numeric Strings and `undefined`:** If the operand is `undefined` or a string that cannot be parsed into a valid number (e.g., `"hello"`), the `ToNumeric` operation evaluates to `NaN`. Incrementing `NaN` results in `NaN`.
* **Symbols:** Symbols cannot be coerced into numeric values. Applying the increment operator to a `Symbol` will throw a `TypeError`.

```javascript theme={"dark"}
// Numeric String coerced to Number
let str = "5";
str++; 
console.log(str); // 6 (Variable reassigned to a Number value)

// Non-numeric String coerces to NaN
let text = "hello";
text++;
console.log(text); // NaN

// undefined coerces to NaN
let undef;
undef++;
console.log(undef); // NaN

// BigInt remains BigInt
let big = 10n;
big++;
console.log(big); // 11n (Type is still BigInt)

// Boolean coerced to Number
let bool = true;
++bool;
console.log(bool); // 2 (true coerced to 1, then incremented)

// Symbol throws TypeError
let sym = Symbol("id");
sym++; // TypeError: Cannot convert a Symbol value to a number
```

## Invalid Operands

Because the `++` operator must mutate its operand, it cannot be applied to r-values such as literals or the evaluated results of expressions. Attempting to do so results in a `SyntaxError` during the parsing phase.

```javascript theme={"dark"}
5++; // SyntaxError: Invalid left-hand side expression in postfix operation
(x + y)++; // SyntaxError: Invalid left-hand side expression in postfix operation
```

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