Mercurial > js4py
comparison core-javascript/equality.rst @ 204:45e7d5e8fa97
Use double backticks for inline code
| author | Radomir Dopieralski <radomir.dopieralski@allegro.pl> |
|---|---|
| date | Wed, 16 May 2012 16:53:27 +0200 |
| parents | 6ea48585f70c |
| children | a808230bc5dd |
comparison
equal
deleted
inserted
replaced
| 203:92c876338c31 | 204:45e7d5e8fa97 |
|---|---|
| 149 .. code-block:: javascript | 149 .. code-block:: javascript |
| 150 | 150 |
| 151 js> +a === +b | 151 js> +a === +b |
| 152 true | 152 true |
| 153 | 153 |
| 154 When the value cannot be converted to a number, you will get a `NaN` value. | 154 When the value cannot be converted to a number, you will get a ``NaN`` value. |
| 155 `NaN` is never equal to anything, even to itself. | 155 `NaN` is never equal to anything, even to itself. |
| 156 | 156 |
| 157 Alternatively, you can use the `parseInt` and `parseFloat` functions to convert | 157 Alternatively, you can use the ``parseInt`` and ``parseFloat`` functions to convert |
| 158 strings to number -- their behavior is slightly different, as they will silently | 158 strings to number -- their behavior is slightly different, as they will silently |
| 159 ignore all non-number characters in the string. | 159 ignore all non-number characters in the string. |
| 160 | 160 |
| 161 .. code-block:: javascript | 161 .. code-block:: javascript |
| 162 | 162 |
| 163 js> parseInt('3abc1') | 163 js> parseInt('3abc1') |
| 164 3 | 164 3 |
| 165 js> +'3abc1' | 165 js> +'3abc1' |
| 166 NaN | 166 NaN |
| 167 | 167 |
| 168 Because `NaN` is never equal to anything, even itself, you cannot check whether | 168 Because ``NaN`` is never equal to anything, even itself, you cannot check whether |
| 169 you got `NaN` as a result with `==` or `===`. You have to use the `isNaN` function | 169 you got ``NaN`` as a result with ``==`` or ``===``. You have to use the ``isNaN`` |
| 170 for that. | 170 function for that. |
| 171 | 171 |
| 172 Compare as boolean | 172 Compare as boolean |
| 173 ------------------ | 173 ------------------ |
| 174 | 174 |
| 175 To convert an expression to a boolean value, it's most convenient to use the | 175 To convert an expression to a boolean value, it's most convenient to use the |
| 176 `!` boolean negation operator twice, like this: | 176 ``!`` boolean negation operator twice, like this: |
| 177 | 177 |
| 178 .. code-block:: javascript | 178 .. code-block:: javascript |
| 179 | 179 |
| 180 js> !!0 === !!'' | 180 js> !!0 === !!'' |
| 181 true | 181 true |
