@@ -4,19 +4,22 @@ attribution: jQuery Fundamentals
44---
55Basic operators allow you to manipulate values.
66
7- <javascript caption =" Concatenation " >
7+ ``` js
8+ // Concatenation
89var foo = ' hello' ;
910var bar = ' world' ;
1011console .log (foo + ' ' + bar); // 'hello world'
11- </ javascript >
12+ ```
1213
13- <javascript caption =" Multiplication and division " >
14+ ``` js
15+ // Multiplication and division
14162 * 3 ;
15172 / 3 ;
16- </ javascript >
18+ ```
1719
18- <javascript caption =" Incrementing and decrementing " >
19- The pre-increment operator increments the operand before any further processing.
20+ ``` js
21+ // Incrementing and decrementing
22+ // The pre-increment operator increments the operand before any further processing.
2023// pre-increment
2124var i = 1 ;
2225console .log (++ i); // => 2
@@ -27,41 +30,45 @@ The post-increment operator increments the operand after processing it.
2730var i = 1 ;
2831console .log (i++ ); // => 1. This is because i was processed first
2932console .log (i); // => 2. This is because the operand was incremented after processing in the previous step.
30- </ javascript >
33+ ```
3134
3235## Operations on Numbers & Strings
3336
3437In JavaScript, numbers and strings will occasionally behave in ways you might
3538not expect.
3639
37- <javascript caption =" Addition vs. Concatenation " >
40+ ``` js
41+ // Addition vs. Concatenation
3842var foo = 1 ;
3943var bar = ' 2' ;
4044console .log (foo + bar); // 12. uh oh
41- </ javascript >
45+ ```
4246
43- <javascript caption =" Forcing a string to act as a number " >
47+ ``` js
48+ // Forcing a string to act as a number
4449var foo = 1 ;
4550var bar = ' 2' ;
4651
4752// coerce the string to a number
4853console .log (foo + Number (bar));
49- </ javascript >
54+ ```
5055
5156The Number constructor, when called as a function (like above) will have the
5257effect of casting its argument into a number. You could also use the unary plus
5358operator, which does the same thing:
5459
55- <javascript caption =" Forcing a string to act as a number (using the unary-plus operator) " >
60+ ``` js
61+ // Forcing a string to act as a number (using the unary-plus operator)
5662console .log (foo + + bar);
57- </ javascript >
63+ ```
5864
5965## Logical Operators
6066
6167Logical operators allow you to evaluate a series of operands using AND and OR
6268operations.
6369
64- <javascript caption =" Logical AND and OR operators " >
70+ ``` js
71+ // Logical AND and OR operators
6572var foo = 1 ;
6673var bar = 0 ;
6774var baz = 2 ;
@@ -72,7 +79,7 @@ bar || foo; // returns 1, which is true
7279foo && bar; // returns 0, which is false
7380foo && baz; // returns 2, which is true
7481baz && foo; // returns 1, which is true
75- </ javascript >
82+ ```
7683
7784Though it may not be clear from the example, the ` || ` operator returns the value
7885of the first truthy operand, or, in cases where neither operand is truthy,
@@ -83,7 +90,7 @@ truthy.
8390Be sure to see the section called “Truthy and Falsy Things” for more
8491details on which values evaluate to true and which evaluate to false.
8592
86- <div class =" note " markdown = " 1 " >
93+ <div class =" note " >
8794You'll sometimes see developers use these logical operators for flow control
8895instead of using if statements. For example:
8996
@@ -106,7 +113,8 @@ comfortable with what it means and how you can expect it to behave.
106113Comparison operators allow you to test whether values are equivalent or whether
107114values are identical.
108115
109- <javascript caption =" Comparison operators " >
116+ ``` js
117+ // Comparison operators
110118var foo = 1 ;
111119var bar = 0 ;
112120var baz = ' 1' ;
@@ -123,4 +131,4 @@ foo === parseInt(baz); // returns true
123131foo > bim; // returns false
124132bim > baz; // returns true
125133foo <= baz; // returns true
126- </ javascript >
134+ ```
0 commit comments