Skip to content

addDefault

The addDefault function returns a custom default value when the input is null or undefined.

{input | addDefault:customDefault}
  • input (any): The value to check
  • customDefault (any): The value to return if input is null or undefined
  • The original input if it’s not null or undefined
  • The customDefault value if input is null or undefined
{null | addDefault:"N/A"}
// Returns: "N/A"
{"Active" | addDefault:"Unknown"}
// Returns: "Active"
{undefined | addDefault:"No data"}
// Returns: "No data"
{"" | addDefault:"Empty"}
// Returns: "" (empty string is not null/undefined)
{vulnerability.cvss_score | addDefault:"Not scored"}
// Returns CVSS score or "Not scored" if null
{user.loginCount | addDefault:0}
// Returns login count or 0 if null
  • Handling missing data in reports
  • Providing fallback values for optional fields
  • Ensuring consistent display of empty values
  • Default values for configuration settings
  • Placeholder text for undefined properties

This function only checks for null and undefined. Empty strings, zero, and false are considered valid values and will not trigger the default.