Skip to content

Commit

Permalink
object.is polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
karan1205 committed Mar 19, 2022
1 parent 47b364d commit e58c2bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Js/core/Object/is/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Object.is()

The Object.is() method determines whether two values are the same value.

```Object.is(value1, value2);```
16 changes: 16 additions & 0 deletions Js/core/Object/is/object.is.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Object.is()
*/
if (!Object.is) {
Object.is = function(value1, value2) {
// Check -0
if(value1 === 0 && value2 === 0) {
return 1/value1 === 1/value2;
}
// Check NaN
if(value1 !== value1) {
return value2 !== value2;
}
return value1 === value2;
}
}

0 comments on commit e58c2bf

Please sign in to comment.