Skip to content

Commit 3abbf7c

Browse files
committed
document short-circuiting
1 parent 998efab commit 3abbf7c

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

www/docs.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,26 @@ Comparisons can be combined via the `and`, `or` and `not` expressions in the usu
694694
add .highlight to the closest <form/>
695695
~~~
696696

697+
Note that `and` and `or` will short circuit in the normal manner:
698+
699+
~~~ hyperscript
700+
if false and foo() # foo() will not execute
701+
~~~
702+
703+
with one important caveat: if the first expression returns a Promise rather than a synchronous value, it will be interpreted
704+
as truthy:
705+
706+
~~~ hyperscript
707+
if returnsPromise() and foo() # foo() will execute, even if the promise resolves to false
708+
~~~
709+
710+
To work around this, you can move the promise-based value out to a separate statement:
711+
712+
~~~ hyperscript
713+
get returnsPromise()
714+
if the result and foo() # foo() will not execute if promise resolves to false
715+
~~~
716+
697717
#### Loops {#loops}
698718

699719
The [repeat command](/commands/repeat) is the looping mechanism in hyperscript.

0 commit comments

Comments
 (0)