Skip to content

Commit

Permalink
feat: explain coercion of falsy and truthy values
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Jan 26, 2024
1 parent b46ddeb commit 596ce33
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion content/actions/learn-github-actions/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ As part of an expression, you can use `boolean`, `null`, `number`, or `string` d
| `number` | Any number format supported by JSON. |
| `string` | You don't need to enclose strings in `{% raw %}${{{% endraw %}` and `{% raw %}}}{% endraw %}`. However, if you do, you must use single quotes (`'`) around the string. To use a literal single quote, escape the literal single quote using an additional single quote (`''`). Wrapping with double quotes (`"`) will throw an error. |

Note that in conditionals, falsy values (`false`, `0`, `-0`, `""`, `''`, `null`) are coerced to `false` and truthy (`true` and other non-falsy values) are coerced to `true`.

### Example of literals

{% raw %}
Expand Down Expand Up @@ -126,7 +128,7 @@ env:
{% endraw %}

In this example, we're using a ternary operator to set the value of the `MY_ENV_VAR` environment variable based on whether the {% data variables.product.prodname_dotcom %} reference is set to `refs/heads/main` or not. If it is, the variable is set to `value_for_main_branch`. Otherwise, it is set to `value_for_other_branches`.
It is important to note that the first value after the `&&` condition must be `truthy` otherwise the value after the `||` will always be returned.
It is important to note that the first conditional after the `&&` must be `true`. Otherwise, the value after the `||` will always be returned.

## Functions

Expand Down

0 comments on commit 596ce33

Please sign in to comment.