Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated equality examples to reflect === semantics #66

Merged
merged 4 commits into from
Sep 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,33 @@ assert(#{ a: 1, b: 2 } === #{ b: 2, a: 1 });

`Record` and `Tuple` types are completely and deeply constant, if they have the same values stored, they will be considered strictly equal.

[Each of the four JS equality algorithms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness) gives the same result when comparing records or tuples:
`===` and `==` follows `SameValue` equality when comparing values inside `Record` or `Tuple`. Further
discussion on this will be found [here](https://github.com/rricard/proposal-const-value-types/issues/65).

```js
// strict equality
assert(#{ a: 1} === #{ a: 1 });
assert(#{ a: 1 } === #{ a: 1 });
assert(#[1] === #[1]);

// abstract equality comparison
assert(#{ a: 1} == #{ a: 1 });
assert(#{ a: 1 } == #{ a: 1 });
assert(#[1] == #[1]);

// SameValue
assert(#{ a: -0 } !== #{ a: +0 });
assert(#[-0] !== #[+0]);
assert(#{ a: NaN } === #{ a: NaN });
assert(#[NaN] === #[NaN]);

assert(#{ a: -0 } != #{ a: +0 });
assert(#[-0] != #[+0]);
assert(#{ a: NaN } == #{ a: NaN });
assert(#[NaN] == #[NaN]);

assert(!Object.is(#{ a: -0 }, #{ a: +0 }));
assert(!Object.is(#[-0], #[+0]));
assert(Object.is(#{ a: NaN }, #{ a: NaN }));
assert(Object.is(#[NaN], #[NaN]));

// SameValueZero
assert(new Map().set(#{ a: 1 }, true).get(#{ a: 1 }));
assert(new Map().set(#[1], true).get(#[1]));

// SameValue
assert(Object.is(#{ a: 1}, #{ a: 1 }));
assert(Object.is(#[1], #[1]));
```

# `Record` and `Tuple` Globals
Expand Down