Skip to content

DOMException: code property ​

The code property is the legacy numeric code the web standards give the name.

Value ​

A number.

  • Read-only. Assigning to it throws TypeError, and the value doesn't change.
  • Determined by name; it can't be given separately.
namecodeConstant
'IndexSizeError'1INDEX_SIZE_ERR
'HierarchyRequestError'3HIERARCHY_REQUEST_ERR
'WrongDocumentError'4WRONG_DOCUMENT_ERR
'InvalidCharacterError'5INVALID_CHARACTER_ERR
'NoModificationAllowedError'7NO_MODIFICATION_ALLOWED_ERR
'NotFoundError'8NOT_FOUND_ERR
'NotSupportedError'9NOT_SUPPORTED_ERR
'InUseAttributeError'10INUSE_ATTRIBUTE_ERR
'InvalidStateError'11INVALID_STATE_ERR
'SyntaxError'12SYNTAX_ERR
'InvalidModificationError'13INVALID_MODIFICATION_ERR
'NamespaceError'14NAMESPACE_ERR
'InvalidAccessError'15INVALID_ACCESS_ERR
'TypeMismatchError'17TYPE_MISMATCH_ERR
'SecurityError'18SECURITY_ERR
'NetworkError'19NETWORK_ERR
'AbortError'20ABORT_ERR
'URLMismatchError'21URL_MISMATCH_ERR
'QuotaExceededError'22QUOTA_EXCEEDED_ERR
'TimeoutError'23TIMEOUT_ERR
'InvalidNodeTypeError'24INVALID_NODE_TYPE_ERR
'DataCloneError'25DATA_CLONE_ERR
Any other name, including 'NotAllowedError', 'OperationError', and names you make up0None

Names such as 'NotAllowedError' and 'OperationError' have no legacy numeric code, so their code is 0. To tell what went wrong, check name, not code.

code isn't the iOS system's error code. When the error comes from the system, the system's error code is on cause.code; see The original system error.

Examples ​

js
const controller = new AbortController();
controller.abort();
const reason = controller.signal.reason;
if (reason instanceof DOMException) {
  console.log(reason.name, reason.code, reason.code === DOMException.ABORT_ERR);
}

Result: Prints AbortError 20 true.

See also ​