README.md (2590B)
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 # isSameValue 22 23 > Test if two arguments are the same value. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isSameValue = require( '@stdlib/assert/is-same-value' ); 31 ``` 32 33 #### isSameValue( a, b ) 34 35 Tests if two arguments `a` and `b` are the same value. 36 37 ```javascript 38 var bool = isSameValue( false, false ); 39 // returns true 40 41 bool = isSameValue( '', '' ); 42 // returns true 43 44 bool = isSameValue( {}, {} ); 45 // returns false 46 ``` 47 48 In contrast to the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the same value. 49 50 <!-- eslint-disable no-compare-neg-zero, use-isnan --> 51 52 ```javascript 53 var bool = ( 0.0 === -0.0 ); 54 // returns true 55 56 bool = isSameValue( 0.0, -0.0 ); 57 // returns false 58 59 bool = isSameValue( -0.0, -0.0 ); 60 // returns true 61 62 bool = ( NaN === NaN ); 63 // returns false 64 65 bool = isSameValue( NaN, NaN ); 66 // returns true 67 ``` 68 69 </section> 70 71 <!-- /.usage --> 72 73 <section class="notes"> 74 75 ## Notes 76 77 - The function implements the [SameValue Algorithm][ecma-262-same-value-algorithm] as specified in ECMAScript 5. 78 79 </section> 80 81 <!-- /.notes --> 82 83 <section class="examples"> 84 85 ## Examples 86 87 <!-- eslint no-undef: "error" --> 88 89 ```javascript 90 var isSameValue = require( '@stdlib/assert/is-same-value' ); 91 92 var bool = isSameValue( true, true ); 93 // returns true 94 95 bool = isSameValue( true, false ); 96 // returns false 97 98 bool = isSameValue( 'beep', 'beep' ); 99 // returns true 100 101 bool = isSameValue( 3.14, 3.14 ); 102 // returns true 103 104 bool = isSameValue( null, null ); 105 // returns true 106 107 bool = isSameValue( 0.0, 0.0 ); 108 // returns true 109 110 bool = isSameValue( -0.0, 0.0 ); 111 // returns false 112 113 bool = isSameValue( NaN, NaN ); 114 // returns true 115 116 bool = isSameValue( {}, {} ); 117 // returns false 118 119 bool = isSameValue( [], [] ); 120 // returns false 121 122 bool = isSameValue( isSameValue, isSameValue ); 123 // returns true 124 ``` 125 126 </section> 127 128 <!-- /.examples --> 129 130 <section class="links"> 131 132 [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12 133 134 </section> 135 136 <!-- /.links -->