manual.yml: fix references to javascript, and clarify semantics of == (#2645)

remove inaccurate and confusing references to javascript; clarify semantics of ==
This commit is contained in:
pkoppstein authored and GitHub committed 2023-07-03 12:35:41 +09:00
1 parent 4b5fcb936f
commit 3c76a5b3f3
2 files changed
+24 -8

No files matched your search

+16 -8
View File
@@ -559,7 +559,7 @@ sections:
hashes with only string keys), and "null". hashes with only string keys), and "null".
Booleans, null, strings and numbers are written the same way as Booleans, null, strings and numbers are written the same way as
in javascript. Just like everything else in jq, these simple in JSON. Just like everything else in jq, these simple
values take an input and produce an output - `42` is a valid jq values take an input and produce an output - `42` is a valid jq
expression that takes an input, ignores it, and returns 42 expression that takes an input, ignores it, and returns 42
instead. instead.
@@ -2116,16 +2116,24 @@ sections:
- title: "`==`, `!=`" - title: "`==`, `!=`"
body: | body: |
The expression 'a == b' will produce 'true' if the result of a and b The expression 'a == b' will produce 'true' if the results of evaluating
are equal (that is, if they represent equivalent JSON documents) and a and b are equal (that is, if they represent equivalent JSON values) and
'false' otherwise. In particular, strings are never considered equal 'false' otherwise. In particular, strings are never considered equal
to numbers. If you're coming from JavaScript, jq's == is like to numbers. In checking for the equality of JSON objects, the ordering of keys
JavaScript's === - considering values equal only when they have the is irrelevant. If you're coming from JavaScript, please note that jq's `==` is like
same type as well as the same value. JavaScript's `===`, the "strict equality" operator.
!= is "not equal", and 'a != b' returns the opposite value of 'a == b' != is "not equal", and 'a != b' returns the opposite value of 'a == b'
examples: examples:
- program: '. == false'
input: 'null'
output: ['false']
- program: '. == {"b": {"d": (4 + 1e-20), "c": 3}, "a":1}'
input: '{"a":1, "b": {"c": 3, "d": 4}}'
output: ['true']
- program: '.[] == 1' - program: '.[] == 1'
input: '[1, 1.0, "1", "banana"]' input: '[1, 1.0, "1", "banana"]'
output: ['true', 'true', 'false', 'false'] output: ['true', 'true', 'false', 'false']
@@ -2145,8 +2153,8 @@ sections:
"truthiness" than is found in JavaScript or Python, but it "truthiness" than is found in JavaScript or Python, but it
means that you'll sometimes have to be more explicit about means that you'll sometimes have to be more explicit about
the condition you want. You can't test whether, e.g. a the condition you want. You can't test whether, e.g. a
string is empty using `if .name then A else B end`, you'll string is empty using `if .name then A else B end`; you'll
need something more like `if .name == "" then A else B end` instead. need something like `if .name == "" then A else B end` instead.
If the condition `A` produces multiple results, then `B` is evaluated If the condition `A` produces multiple results, then `B` is evaluated
once for each result that is not false or null, and `C` is evaluated once for each result that is not false or null, and `C` is evaluated
+8
View File
@@ -668,6 +668,14 @@ strptime("%Y-%m-%dT%H:%M:%SZ")|mktime
"2015-03-05T23:51:47Z" "2015-03-05T23:51:47Z"
1425599507 1425599507
. == false
null
false
. == {"b": {"d": (4 + 1e-20), "c": 3}, "a":1}
{"a":1, "b": {"c": 3, "d": 4}}
true
.[] == 1 .[] == 1
[1, 1.0, "1", "banana"] [1, 1.0, "1", "banana"]
true true