Undefined values: Difference between revisions
Content added Content deleted
(Added zkl) |
(jq) |
||
Line 558: | Line 558: | ||
a === void 0; // true |
a === void 0; // true |
||
b === void 0; // throws a ReferenceError</lang> |
b === void 0; // throws a ReferenceError</lang> |
||
=={{header|jq}}== |
|||
In jq as in JSON, null can usually be used to represent an undefined or unspecified value. However, in jq, 1/0 does not yield null: |
|||
<lang sh>$ jq -n '1/0 == null' |
|||
false</lang> |
|||
It should also be noted that in jq, null can combine with other values to form non-null values. Specifically, for any JSON entity, e, |
|||
both null + e and e + null evaluate to e. This is often convenient as it avoids having to handle edge cases specially. |
|||
For example, suppose it is agreed that the "sum" of the elements of an empty array should be null. Then one can simply write: |
|||
<lang jq>def sum: reduce .[] as $x (null; . + $x);</lang> |
|||
=={{header|Logo}}== |
=={{header|Logo}}== |