The isFalsey helper returns true if the input value is absent or empty, and false if it has a meaningful value. Use it to validate optional fields, check for missing data, or build conditional logic around empty values.
Syntax
{{isFalsey value}}
value -- The value to evaluate. Required.
Values that return true
| Value | Type |
|---|---|
false |
Boolean |
0 |
Integer |
"" |
Empty string |
null |
Null |
undefined |
Undefined |
NaN |
Not a number |
All other values -- non-empty strings, non-zero numbers, arrays, and objects -- return false.
Examples
Evaluate a mix of present and absent values
{{isFalsey record.a}}
{{isFalsey record.b}}
{{isFalsey record.c}}
{{isFalsey record.d}}
{{isFalsey record.e}}
Input:
{
"record": {
"a": 1,
"b": 0,
"c": "hello",
"d": "",
"e": null
}
}
Output:
false true false true true
record.a (1) and record.c ("hello") have meaningful values, so they return false. record.b (0), record.d (""), and record.e (null) are absent or empty, so they return true.
Use in a conditional block
{{#if (isFalsey record.value)}}
Value is absent
{{else}}
Value is present
{{/if}}
Input:
{ "record": { "value": "" } }
Output: Value is absent
Wrap isFalsey in parentheses to use it as an inline expression inside #if.
Usage notes
- Wrap
isFalseyin parentheses when using it as an inline expression:{{#if (isFalsey value)}}. - The string
"0"and the string"false"are non-empty strings and returnfalse-- only the integer0and the booleanfalsereturntrue. - To check whether a value is present rather than absent, use the isTruthy helper instead.