Dasel
v3
v3
  • Getting started
    • Introduction
    • Installation
    • Concepts
      • Expressions
      • Branches
  • Syntax
    • Whitespace
    • Types/Literals
    • String concatenation
    • Arrays/slices
    • Objects/maps
    • Conditionals
    • Spread
    • Coalesce
  • Input/Output
    • Read/Write formats
    • Stdin
    • Stdout
    • Variables
    • Read/Writer flags
  • Functions
    • add
    • min
    • max
    • reverse
    • toString
    • toInt
    • toFloat
    • typeOf
    • map
    • filter
    • sortBy
    • parse
    • base64e
    • base64d
Powered by GitBook
On this page
  • Examples
  • Check if a property or index exists
  • Default values when something doesn't exist
  • Chaining
  1. Syntax

Coalesce

The coalesce ?? operator can be used to provide default values when the given path does not exist, or causes some error.

The operator will pass through to the secondary value if:

  • A given map key doesn't exist

  • A given array index doesn't exist

  • The given expressions returns null

  • An operation is performed on an invalid type

Examples

Check if a property or index exists

if ($someArray[10] ?? false) {
    // exists
} else {
    // does not exist
}

if ($someMap.foo ?? false) {
    // exists
} else {
    // does not exist
}

Default values when something doesn't exist

foo.bar.baz ?? "my sensible default"

Chaining

The coalesce operator can be chained, with items towards the left taking prescedence.

foo ?? bar ?? baz ?? false
PreviousSpreadNextRead/Write formats

Last updated 7 months ago