README.md (2718B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # isSameValueZero 22 23 > Test if two arguments are the same value. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isSameValueZero = require( '@stdlib/assert/is-same-value-zero' ); 31 ``` 32 33 #### isSameValueZero( a, b ) 34 35 Tests if two arguments `a` and `b` are the same value. 36 37 ```javascript 38 var bool = isSameValueZero( false, false ); 39 // returns true 40 41 bool = isSameValueZero( '', '' ); 42 // returns true 43 44 bool = isSameValueZero( {}, {} ); 45 // returns false 46 ``` 47 48 In contrast to the strict equality operator `===`, the function treats `NaNs` as the same value. 49 50 <!-- eslint-disable use-isnan --> 51 52 ```javascript 53 var bool = ( NaN === NaN ); 54 // returns false 55 56 bool = isSameValueZero( NaN, NaN ); 57 // returns true 58 ``` 59 60 In contrast to the [SameValue Algorithm][@stdlib/assert/is-same-value], the function does **not** distinguish between `+0` and `-0`. 61 62 <!-- eslint-disable no-compare-neg-zero --> 63 64 ```javascript 65 var bool = ( 0.0 === -0.0 ); 66 // returns true 67 68 bool = isSameValueZero( 0.0, -0.0 ); 69 // returns true 70 71 bool = isSameValueZero( -0.0, 0.0 ); 72 // returns true 73 ``` 74 75 </section> 76 77 <!-- /.usage --> 78 79 <section class="notes"> 80 81 </section> 82 83 <!-- /.notes --> 84 85 <section class="examples"> 86 87 ## Examples 88 89 <!-- eslint no-undef: "error" --> 90 91 ```javascript 92 var isSameValueZero = require( '@stdlib/assert/is-same-value-zero' ); 93 94 var bool = isSameValueZero( true, true ); 95 // returns true 96 97 bool = isSameValueZero( true, false ); 98 // returns false 99 100 bool = isSameValueZero( 'beep', 'beep' ); 101 // returns true 102 103 bool = isSameValueZero( 3.14, 3.14 ); 104 // returns true 105 106 bool = isSameValueZero( null, null ); 107 // returns true 108 109 bool = isSameValueZero( 0.0, 0.0 ); 110 // returns true 111 112 bool = isSameValueZero( -0.0, 0.0 ); 113 // returns true 114 115 bool = isSameValueZero( NaN, NaN ); 116 // returns true 117 118 bool = isSameValueZero( {}, {} ); 119 // returns false 120 121 bool = isSameValueZero( [], [] ); 122 // returns false 123 124 bool = isSameValueZero( isSameValueZero, isSameValueZero ); 125 // returns true 126 ``` 127 128 </section> 129 130 <!-- /.examples --> 131 132 <section class="links"> 133 134 [@stdlib/assert/is-same-value]: https://www.npmjs.com/package/@stdlib/assert/tree/main/is-same-value 135 136 </section> 137 138 <!-- /.links -->