Skip to content

Commit e3e1bf5

Browse files
committed
Put operators in regular code font
1 parent 62199ee commit e3e1bf5

8 files changed

Lines changed: 58 additions & 58 deletions

File tree

01_values.txt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ a new number from them. Here is what they look like in JavaScript:
145145
100 + 4 * 11
146146
----
147147

148-
(((\* operator)))(((+ operator)))The “+” and “*” symbols are called
148+
(((\* operator)))(((+ operator)))The `+` and `*` symbols are called
149149
_operators_. The first stands for addition, and the second stands for
150150
multiplication. Putting an operator between two values will
151151
(((application,of operators)))apply it to those values and produce a
@@ -163,21 +163,21 @@ parentheses.
163163
----
164164

165165
(((division)))(((subtraction)))(((- operator)))(((/ operator)))For
166-
subtraction, there is the “-” operator, and division can be done with
167-
the “/” operator.
166+
subtraction, there is the `-` operator, and division can be done with
167+
the `/` operator.
168168

169169
When operators appear together without parentheses, the order in which
170170
they are applied is determined by the _((precedence))_ of the
171171
operators. The example shows that multiplication comes before
172-
addition. “/” has the same precedence as “*”. Likewise for “+” and
173-
“-”. When multiple operators with the same precedence appear next to
172+
addition. `/` has the same precedence as `*`. Likewise for `+` and
173+
`-`. When multiple operators with the same precedence appear next to
174174
each other (as in `1 - 2 + 1`), they are applied left to right.
175175

176176
These rules of precedence are not something you should worry about.
177177
When in doubt, just add parentheses.
178178

179179
(((remainder operation)))(((% operator)))There is one more arithmetic
180-
operator, which you might not recognize. The “%” symbol is used to
180+
operator, which you might not recognize. The `%` symbol is used to
181181
represent the _remainder_ operation. `X % Y` is the remainder of
182182
dividing `X` by `Y`. For example, `314 % 100` produces `14`, and `144
183183
% 12` gives `0`. Remainder's precedence is the same as that of
@@ -257,7 +257,7 @@ character is written like "\n"`” can be written:
257257
----
258258

259259
(((+ operator)))(((concatenation)))Strings cannot be divided,
260-
multiplied, or subtracted, but the “+” operator _can_ be used on them.
260+
multiplied, or subtracted, but the `+` operator _can_ be used on them.
261261
It does not add, but it __concatenates__—it glues two strings together.
262262
The following line will produce the string `"concatenate"`:
263263

@@ -322,7 +322,7 @@ console.log(3 < 2)
322322
----
323323

324324
(((> operator)))(((< operator)))(((greater than)))(((less
325-
than)))(((comparing)))The “>” and “<” signs are the traditional symbols
325+
than)))(((comparing)))The `>` and `<` signs are the traditional symbols
326326
for “is greater than” and “is less than”, respectively. They are binary operators.
327327
Applying them results in a boolean value that indicates
328328
whether they hold true in this case.
@@ -348,9 +348,9 @@ JavaScript goes over them from left to right, comparing the numeric
348348
codes of the characters one by one.
349349

350350
(((>= operator)))(((<= operator)))(((== operator)))(((!=
351-
operator)))Other similar operators are “>=” (greater than or equal
352-
to), \<= (less than or equal to), “==” (equal to), and
353-
“!=” (not equal to).
351+
operator)))Other similar operators are `>=` (greater than or equal
352+
to), `\<=` (less than or equal to), `==` (equal to), and
353+
`!=` (not equal to).
354354

355355
[source,javascript]
356356
----
@@ -377,7 +377,7 @@ applied to Boolean values themselves. JavaScript supports three
377377
logical operators: _and_, _or_, and _not_. These can be used to
378378
“reason” about Booleans.
379379

380-
(((&& operator)))The “&&” operator represents logical _and_. It is a
380+
(((&& operator)))The `&&` operator represents logical _and_. It is a
381381
binary operator, and its result is true only if both the values
382382
given to it are true.
383383

@@ -389,7 +389,7 @@ console.log(true && true)
389389
// → true
390390
----
391391

392-
(((|| operator)))The “||” operator denotes logical _or_. It produces
392+
(((|| operator)))The `||` operator denotes logical _or_. It produces
393393
true if either of the values given to it is true.
394394

395395
[source,javascript]
@@ -401,14 +401,14 @@ console.log(false || false)
401401
----
402402

403403
(((negation)))(((! operator)))_Not_ is written as an exclamation mark
404-
(“!”). It is a unary operator that flips the value given to it—`!true`
404+
(`!`). It is a unary operator that flips the value given to it—`!true`
405405
produces `false` and `!false` gives `true`.
406406

407407
(((precedence)))When mixing these Boolean operators with arithmetic
408408
and other operators, it is not always obvious when parentheses are
409409
needed. In practice, you can usually get by with knowing that of the
410-
operators we have seen so far, “||” has the lowest precedence, then
411-
comes “&&”, then the comparison operators (“>”, “==”, and so on), and
410+
operators we have seen so far, `||` has the lowest precedence, then
411+
comes `&&`, then the comparison operators (`>`, `==`, and so on), and
412412
then the rest. This order has been chosen such that, in typical
413413
expressions like the following one, as few parentheses as possible are
414414
necessary:
@@ -489,7 +489,7 @@ produced. Further arithmetic operations on `NaN` keep producing
489489
`NaN`, so if you find yourself getting one of those in an unexpected
490490
place, look for accidental type conversions.
491491

492-
(((== operator)))When comparing values of the same type using “==”,
492+
(((== operator)))When comparing values of the same type using `==`,
493493
the outcome is easy to predict: you should get true when both
494494
values are the same. But when the types differ, JavaScript uses a
495495
complicated and confusing set of rules to determine what to do. I will
@@ -508,8 +508,8 @@ console.log(null == 0);
508508

509509
That last piece of behavior is often useful. When you want to
510510
test whether a value has a real value instead of `null`
511-
or `undefined`, you can simply compare it to `null` with the “==” (or
512-
“!=”) operator.
511+
or `undefined`, you can simply compare it to `null` with the `==` (or
512+
`!=`) operator.
513513

514514
(((=== operator)))(((!== operator)))But what if you want to test
515515
whether something refers to the precise value `false`? The rules for
@@ -518,7 +518,7 @@ converting strings and numbers to Boolean values state that `0`,
518518
values count as `true`. Because of this, expressions like `0 == false`
519519
and `"" == false` are also true. For cases like this, where you do
520520
_not_ want any automatic type conversions to happen, there are two
521-
extra operators: === and !==. The first tests whether a value is
521+
extra operators: `===` and `!==`. The first tests whether a value is
522522
precisely equal to the other, and the second tests whether it is not
523523
precisely equal. So `"" === false` is false as expected.
524524

@@ -530,13 +530,13 @@ using the shorter operators.
530530
=== Short-circuiting of logical operators ===
531531

532532
(((|| operator)))(((&& operator)))(((?: operator)))(((operator)))The
533-
logical operators “&&” and “||” handle values of different types in a
533+
logical operators `&&` and `||` handle values of different types in a
534534
peculiar way. They _will_ convert the value on their left side to
535535
boolean type in order to decide what to do, but depending on the
536536
operator and the result of that conversion, they return either the
537537
_original_ left-hand value or the right-hand value.
538538

539-
The “||” operator, for example, will return the value to its left when that can be
539+
The `||` operator, for example, will return the value to its left when that can be
540540
converted to true and will return the value on its right otherwise. This conversion works as
541541
you'd expect for boolean values and should do something analogous for
542542
values of other types.
@@ -554,7 +554,7 @@ to fall back on a default value. If you give it an expression that might produce
554554
an empty value on the left, the value on the right will be used as a replacement
555555
in that case.
556556

557-
The “&&” operator works similarly, but the other way around. When the
557+
The `&&` operator works similarly, but the other way around. When the
558558
value to its left is something that converts to false, it returns that
559559
value, and otherwise it returns the value on its right.
560560

@@ -576,10 +576,10 @@ strings, Booleans, and undefined values.
576576

577577
Such values are created by typing in their name (`true`, `null`) or
578578
value (`13`, `"abc"`). You can combine and transform values with operators. We saw binary
579-
operators for arithmetic (“+”, “-”, “*”, “/”,
580-
and “%”), string concatenation (“+”), comparison (“==”, “!=”,
581-
===”, “!==”, “<”, “>”, “\<=”, “>=”), and logic (“&&”, “||”), as well
582-
as several unary operators (“-” to negate a number, “!” to negate
579+
operators for arithmetic (`+`, `-`, `*`, `/`,
580+
and `%`), string concatenation (`+`), comparison (`==`, `!=`,
581+
`===`, `!==`, `<`, `>`, `\<=`, `>=`), and logic (`&&`, `||`), as well
582+
as several unary operators (`-` to negate a number, `!` to negate
583583
logically, and `typeof` to find a value's type).
584584

585585
This gives you enough information to use JavaScript as a pocket

02_program_structure.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var caught = 5 * 5;
8989
(((var keyword)))And that gives us our second kind of statement. The
9090
special word (_keyword_) `var` indicates that this sentence is going
9191
to define a variable. It is followed by the name of the variable and,
92-
if we want to immediately give it a value, by an “=” operator and an
92+
if we want to immediately give it a value, by an `=` operator and an
9393
expression.
9494

9595
The previous statement creates a variable called `caught` and uses it
@@ -114,7 +114,7 @@ variable name cannot include punctuation, except for the characters
114114
“$” and “_”.
115115

116116
When a variable points at a value, that does not mean it is tied to
117-
that value forever. The “=” operator can be used at any time on
117+
that value forever. The `=` operator can be used at any time on
118118
existing variables to disconnect them from their current value and
119119
have them point to a new one:
120120

@@ -621,7 +621,7 @@ console.log(current);
621621
----
622622

623623
(((remainder operation)))(((% operator)))The trick with the remainder
624-
(“%”) operator is an easy way to test whether a number is divisible by
624+
(`%`) operator is an easy way to test whether a number is divisible by
625625
another number. If it is, the remainder of their division is zero.
626626

627627
The `for` construct in the example does not have a part that checks
@@ -896,7 +896,7 @@ endif::html_target[]
896896

897897
Going over the numbers is clearly a looping job, and selecting what to
898898
print is a matter of conditional execution. Remember the trick of
899-
using the remainder (“%”) operator for checking whether a number is
899+
using the remainder (`%`) operator for checking whether a number is
900900
divisible by another number (has a remainder of zero).
901901

902902
In the first version, there are three possible outcomes for
@@ -906,7 +906,7 @@ The second version of the program has a straightforward solution and a
906906
clever one. The simple way is to add another “branch” to precisely test
907907
the given condition. For the clever method, build up a string containing
908908
the word or words to output, and print either this word or the number
909-
if there is no word, potentially by making elegant use of the “||”
909+
if there is no word, potentially by making elegant use of the `||`
910910
operator.
911911

912912
!!solution!!

03_functions.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,11 @@ with `(1 + 5)` and `(1 * 3)`. The first call tries to find a solution
659659
that starts with `(1 + 5)`, and, using recursion, explores _every_
660660
solution that yields a number smaller than or equal to the target
661661
number. Since it doesn't find a solution that hits the target, it
662-
returns `null` back to the first call. There the “||” operator causes
662+
returns `null` back to the first call. There the `||` operator causes
663663
the call that explores `(1 * 3)` to happen. This search has more
664664
luck, as its first recursive call, through yet _another_ recursive
665665
call, hits upon the target number, 13. This innermost recursive call
666-
returns a string, and each of the “||” operators in the intermediate
666+
returns a string, and each of the `||` operators in the intermediate
667667
calls pass that string along, ultimately returning our solution.
668668

669669
== Growing functions ==

04_data.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ var descriptions = {
271271

272272
(((property,assignment)))(((mutability)))(((= operator)))It is possible to
273273
assign a value to a property expression
274-
with the “=” operator. This will replace the property's value if it
274+
with the `=` operator. This will replace the property's value if it
275275
already existed, or create a new property on the object if it didn't.
276276

277277
To briefly come back to our tentacle model of variable
@@ -807,7 +807,7 @@ after the start index. Strings also have a `slice`
807807
method, which has a similar effect.
808808

809809
(((concat method)))The `concat` method can be used
810-
to glue arrays together, similar to what the “+”
810+
to glue arrays together, similar to what the `+`
811811
operator does for strings. The following
812812
example shows both `concat` and `slice` in action. It
813813
takes an array and an index, and returns a new array
@@ -1154,7 +1154,7 @@ method to add a value. Don't forget to return the array at the end of the
11541154
function.
11551155

11561156
Since the end boundary is inclusive, you'll need to use the “\<=”
1157-
operator rather than simply “<” to check for the end of your loop.
1157+
operator rather than simply `<` to check for the end of your loop.
11581158

11591159
To check whether the optional step argument was given, either check
11601160
`arguments.length` or compare the value of the argument to
@@ -1164,7 +1164,7 @@ To check whether the optional step argument was given, either check
11641164
Having `range` understand negative step values is probably best done
11651165
by writing two separate loops—one for counting up, one for
11661166
counting down—because the comparison that checks whether the loop is
1167-
finished needs to be “>=” rather than “\<=” when counting downwards.
1167+
finished needs to be `>=` rather than “\<=” when counting downwards.
11681168

11691169
It might also be worthwhile to use a different default step, namely
11701170
-1, when the end of the range is smaller than the start. That way,
@@ -1332,15 +1332,15 @@ that's in this list's `rest` property.
13321332

13331333
=== Deep comparison ===
13341334

1335-
The “==” operator compares objects by identity. But sometimes, you would
1335+
The `==` operator compares objects by identity. But sometimes, you would
13361336
prefer to compare the values of their actual properties.
13371337

13381338
Write a function, `deepEqual`, that takes two values and returns true
13391339
only if they are the same value, or are objects with the same properties
13401340
whose values are also equal when compared with a recursive call to
13411341
`deepEqual`.
13421342

1343-
To find out whether to compare two things by identity (use the ===
1343+
To find out whether to compare two things by identity (use the `===`
13441344
operator for that) or by looking at their properties, you can use the `typeof` operator.
13451345
If it produces `"object"` for both values, you should do a deep comparison. But
13461346
you have to take one silly exception into account: by a
@@ -1370,7 +1370,7 @@ endif::html_target[]
13701370
Your test for whether you are dealing with a real object will look
13711371
something like `typeof x == "object" && x != null`. Be careful to only
13721372
compare properties when _both_ arguments are objects. In all other
1373-
cases you can just immediately return the result of applying ===.
1373+
cases you can just immediately return the result of applying `===`.
13741374

13751375
Use a `for`/`in` loop to go over the properties. You need to test
13761376
whether both objects have the same set of property names, and whether

07_elife.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ PlantEater.prototype.act = function(context) {
933933
};
934934
----
935935

936-
We'll use the “*” character for plants, so that's what this creature
936+
We'll use the `*` character for plants, so that's what this creature
937937
will look for when it searches for food.
938938

939939
== Bringing it to life ==

08_error.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ properly reported.
641641
In cases where you only need one instance of your error (it
642642
always has the same message) and stack traces are not important, you
643643
can simplify things a little by defining a single error object
644-
rather than a constructor, and comparing exceptions to it with the “==”
644+
rather than a constructor, and comparing exceptions to it with the `==`
645645
operator.
646646

647647
== Assertions ==

0 commit comments

Comments
 (0)