> ## 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 Public Field

Public class fields are properties declared directly within a class body, allowing developers to attach state to class instances without explicitly defining them inside the `constructor` method. By default, fields declared this way are publicly accessible, writable, enumerable, and configurable on the instantiated object.

```javascript theme={"dark"}
class InstanceState {
  // Uninitialized public field (implicitly undefined)
  uninitializedField;

  // Initialized public field
  initializedField = 'default value';

  // Public field assigned to an arrow function
  boundMethod = () => {
    return this.initializedField;
  };
}
```

## Technical Mechanics

**Instance Allocation**
Public fields are created as *own properties* on the instance itself via `[[DefineOwnProperty]]` semantics. They are not attached to the class prototype. This means every time a class is instantiated, a new copy of the field and its evaluated value is allocated in memory.

**Evaluation Timing**
The initialization of public fields is strictly ordered during the object construction phase:

* **Base Classes:** Field initializers are evaluated and assigned immediately *before* the `constructor` body executes.
* **Derived Classes:** Field initializers are evaluated and assigned immediately *after* the `super()` call returns. Attempting to access `this` before `super()` will result in a `ReferenceError`.

```javascript theme={"dark"}
class Base {
  baseField = 10;
  
  constructor() {
    // baseField is already initialized here
    console.log(this.baseField); 
  }
}

class Derived extends Base {
  derivedField = 20;
  
  constructor() {
    // super() must be called before derivedField is initialized
    super(); 
    // derivedField is now initialized
    console.log(this.derivedField); 
  }
}
```

**Lexical Scoping and `this` Binding**
The initializer expression of a public field is evaluated within the class scope. The `this` keyword inside the initializer refers to the instance currently being constructed. When a public field is assigned an arrow function, the arrow function lexically binds `this` to the instance, ensuring the context remains strictly tied to the object regardless of how the method is invoked.

## Static Public Fields

By prepending the `static` keyword, a public field is attached directly to the class constructor object rather than to individual instances.

```javascript theme={"dark"}
class Configuration {
  static defaultTimeout = 5000;
  static environment = 'production';
}

// Accessed via the class itself, not an instance
console.log(Configuration.defaultTimeout); // 5000
```

Static fields are evaluated only once, at the time the class definition is evaluated by the JavaScript engine. They are added as own properties of the class constructor function.

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