Reference for stage 3 is-error#38251
Conversation
|
Preview URLs
Flaws (2)Note! 2 documents with no flaws that don't need to be listed. 🎉 URL:
External URLs (2)URL:
URL:
(comment last updated: 2025-02-24 05:44:43) |
files/en-us/web/javascript/reference/global_objects/error/iserror/index.md
Outdated
Show resolved
Hide resolved
…ror/index.md Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
files/en-us/web/javascript/reference/global_objects/error/iserror/index.md
Outdated
Show resolved
Hide resolved
…ror/index.md Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
files/en-us/web/javascript/reference/global_objects/error/iserror/index.md
Outdated
Show resolved
Hide resolved
|
|
||
| ## Description | ||
|
|
||
| `Error.isError()` checks if the passed value is an {{jsxref("Error")}}. It uses the same mechanism as {{jsxref("Array.isArray()")}}: it performs a _branded check_, similar to the [`in`](/en-US/docs/Web/JavaScript/Reference/Operators/in) operator, for a private property initialized by the {{jsxref("Error/Error", "Error()")}} constructor. |
There was a problem hiding this comment.
I think this is what you are saying?
| `Error.isError()` checks if the passed value is an {{jsxref("Error")}}. It uses the same mechanism as {{jsxref("Array.isArray()")}}: it performs a _branded check_, similar to the [`in`](/en-US/docs/Web/JavaScript/Reference/Operators/in) operator, for a private property initialized by the {{jsxref("Error/Error", "Error()")}} constructor. | |
| `Error.isError()` checks if the passed value is an {{jsxref("Error")}}. It does so by performing a _branded check_ for a private property initialized by the {{jsxref("Error/Error", "Error()")}} constructor. | |
| This is the same mechanism used by {{jsxref("Array.isArray()")}}, which is in turn similar to the mechanism used by the [`in`](/en-US/docs/Web/JavaScript/Reference/Operators/in) operator. |
So how does this work for DOMException ? Its constructor includes the same kind of private property as the error constructor?
There was a problem hiding this comment.
Also, possibly
| `Error.isError()` checks if the passed value is an {{jsxref("Error")}}. It uses the same mechanism as {{jsxref("Array.isArray()")}}: it performs a _branded check_, similar to the [`in`](/en-US/docs/Web/JavaScript/Reference/Operators/in) operator, for a private property initialized by the {{jsxref("Error/Error", "Error()")}} constructor. | |
| `Error.isError()` checks if the passed value is an {{jsxref("Error")}} or `DOMException`. It does so by performing a _branded check_ for a private property initialized by the {{jsxref("Error/Error", "Error()")}} constructor. | |
| This is the same mechanism used by {{jsxref("Array.isArray()")}}, which is in turn similar to the mechanism used by the [`in`](/en-US/docs/Web/JavaScript/Reference/Operators/in) operator. |
There was a problem hiding this comment.
DOMException is supposed to behave like Error so I wouldn't want to imply that they are unrelated things and isError happens to check both. I'm not sure why the in operator reference is removed though—without it it's still hard to conceptualize what "branded check" and "private property" means.
There was a problem hiding this comment.
Both suggestions still mentions in, it's just that this moved to the third sentence. The problem I am trying to fix is that it is hard to parse your sentence.
I'm fine with not mentioning "differentiating" the error types, so ignore my second suggestion and let's just consider the first one, which I will reproduce here:
| `Error.isError()` checks if the passed value is an {{jsxref("Error")}}. It uses the same mechanism as {{jsxref("Array.isArray()")}}: it performs a _branded check_, similar to the [`in`](/en-US/docs/Web/JavaScript/Reference/Operators/in) operator, for a private property initialized by the {{jsxref("Error/Error", "Error()")}} constructor. | |
| `Error.isError()` checks if the passed value is an {{jsxref("Error")}}. It does so by performing a _branded check_ for a private property initialized by the {{jsxref("Error/Error", "Error()")}} constructor. | |
| This is the same mechanism used by {{jsxref("Array.isArray()")}}, which is in turn similar to the mechanism used by the [`in`](/en-US/docs/Web/JavaScript/Reference/Operators/in) operator. |
And I am still interested in
So how does this work for
DOMException? Its constructor includes the same kind of private property as the error constructor?
There was a problem hiding this comment.
So how does this work for
DOMException? Its constructor includes the same kind of private property as the error constructor?
I think I replied in one of the resolved conversations above but yeah that's exactly what happens.
There was a problem hiding this comment.
If you did, I missed it. Sorry. Thanks.
| `Array.isArray()` checks if the passed value is an {{jsxref("Array")}}. It does not check the value's prototype chain, nor does it rely on the `Array` constructor it is attached to. It returns `true` for any value that was created using the array literal syntax or the `Array` constructor. This makes it safe to use with cross-realm objects, where the identity of the `Array` constructor is different and would therefore cause [`instanceof Array`](/en-US/docs/Web/JavaScript/Reference/Operators/instanceof) to fail. | ||
| `Array.isArray()` checks if the passed value is an {{jsxref("Array")}}. It performs a _branded check_, similar to the [`in`](/en-US/docs/Web/JavaScript/Reference/Operators/in) operator, for a private property initialized by the {{jsxref("Array/Array", "Array()")}} constructor. | ||
|
|
||
| See the article ["Determining with absolute accuracy whether or not a JavaScript object is an array"](https://web.mit.edu/jwalden/www/isArray.html) for more details. | ||
| It is a more robust alternative to [`instanceof Array`](/en-US/docs/Web/JavaScript/Reference/Operators/instanceof) because it avoids false positives and false negatives: | ||
|
|
||
| - `Array.isArray()` rejects values that aren't actual `Array` instances, even if they have `Array.prototype` their prototype chain — `instanceof Array` would accept these as it does check the prototype chain. | ||
| - `Array.isArray()` accepts `Array` objects constructed in another realm — `instanceof Array` returns `false` for these because the identity of the `Array` constructor is different across realms. | ||
|
|
||
| `Array.isArray()` also rejects objects with `Array.prototype` in its prototype chain but aren't actual arrays, which `instanceof Array` would accept. | ||
| See the article ["Determining with absolute accuracy whether or not a JavaScript object is an array"](https://web.mit.edu/jwalden/www/isArray.html) for more details. |
…ror/index.md Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
hamishwillee
left a comment
There was a problem hiding this comment.
LGTM. Any idea when the BCD will go in? Should merging be timed to match?
|
BCD is already there: mdn/browser-compat-data#25978 so it's just a matter of publish/deployment I think. I wouldn't mind publishing docs with missing BCD in any case. |
files/en-us/web/javascript/reference/global_objects/error/iserror/index.md
Outdated
Show resolved
Hide resolved
hamishwillee
left a comment
There was a problem hiding this comment.
I wouldn't mind publishing docs with missing BCD in any case.
In that case, we're good to go.
Please see tc39/proposal-is-error#7 for implementation status. This is shipping flagged in Safari and by default in Chrome 134, but not much news from FF yet.