You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Number constructor, when called as a function (as in the above example), will have the effect of casting its argument into a number. The unary plus operator also does the same thing:
58
+
The `Number` constructor, when called as a function (as in the above example), will have the effect of casting its argument into a number. The unary plus operator also does the same thing:
58
59
59
60
```
60
-
// Forcing a string to act as a number (using the unary plus operator):
61
+
// Forcing a string to act as a number (using the unary plus operator).
61
62
console.log( foo + +bar ); // 3
62
63
```
63
64
64
65
## Logical Operators
65
66
66
-
Logical operators allow evaluation of a series of operands using AND (`&&`) and OR (`||`) operations.
67
+
Logical operators allow evaluation of a series of operands using AND (`&&`) and OR (`||`) operations.
67
68
68
69
```
69
70
// Logical AND and OR operators
71
+
70
72
var foo = 1;
71
73
var bar = 0;
72
74
var baz = 2;
@@ -92,10 +94,10 @@ In the above example, the `||` operator returns the value of the first truthy op
92
94
You'll sometimes see developers use these logical operators for flow control instead of using `if` statements. For example:
93
95
94
96
```
95
-
// do something with foo if foo is truthy
97
+
// Do something with foo if foo is truthy.
96
98
foo && doSomething( foo );
97
99
98
-
// set bar to baz if baz is truthy;
100
+
// Set bar to baz if baz is truthy;
99
101
// otherwise, set it to the return value of createBar()
100
102
var bar = baz || createBar();
101
103
```
@@ -108,6 +110,7 @@ Comparison operators allow you to test whether values are equivalent or whether
108
110
109
111
```
110
112
// Comparison operators
113
+
111
114
var foo = 1;
112
115
var bar = 0;
113
116
var baz = "1";
@@ -125,4 +128,5 @@ foo > bim; // false
125
128
bim > baz; // true
126
129
foo <= baz; // true
127
130
```
131
+
128
132
For more information about comparison operators, visit the [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Comparison_Operators"MDN - Comparison Operators").
0 commit comments