Skip to main content

.val()

The .val() method is a convenience wrapper that simplifies reading data. It’s essentially shorthand for .once() but with a more intuitive name for getting values.
The .val() method is experimental. Its behavior and API may change in future versions. Use .once() for production code if you need stable behavior.

Signature

Parameters

function
Function called with the value once it’s loaded.Signature: function(data, key)
  • data - The value at this node
  • key - The property key
object
Options passed through to .once()

Return Value

Returns a GUN chain reference for method chaining.

Examples

Basic Usage

Why .val() Exists

Chaining after .val()

Implementation Details

The .val() method is not directly in the source files provided, but based on the GUN API patterns, it’s typically implemented as:
It’s a thin wrapper around .once() that:
  1. Provides a more semantic name for “get value”
  2. Passes all arguments through to .once()
  3. Returns the same chain for method chaining

.val() vs .once() vs .on()

When to Use .val()

Experimental Status Warning

From the GUN documentation:
The method may:
  • Change behavior in future versions
  • Be renamed or removed
  • Have different return values
  • Gain new features
For production code, use .once() instead:

Callback Context

Async/Await Pattern

Notes

  • .val() is experimental and may change
  • It’s essentially an alias for .once() with a clearer name
  • Use .once() for production code
  • Provides better semantics for “getting a value”
  • Returns immediately; callback fires when data loads
  • Automatically cleans up like .once() does
  • Check GUN release notes for updates to this API