SyntaxError: Ungültige BigInt-Syntax
Der JavaScript-Ausnahmefehler "ungültige BigInt-Syntax" tritt auf, wenn ein String-Wert in ein BigInt
umgewandelt werden soll, aber nicht als Ganzzahl geparst werden konnte.
Meldung
SyntaxError: Cannot convert x to a BigInt (V8-based) SyntaxError: invalid BigInt syntax (Firefox) SyntaxError: Failed to parse String to BigInt (Safari)
Fehlerart
Was ist schiefgelaufen?
Beim Verwenden der BigInt()
-Funktion zur Umwandlung eines Strings in ein BigInt wird der String auf die gleiche Weise geparst wie der Quellcode, und der resultierende Wert muss eine Ganzzahl sein.
Beispiele
>Ungültige Fälle
js
const a = BigInt("1.5");
const b = BigInt("1n");
const c = BigInt.asIntN(4, "8n");
// SyntaxError: invalid BigInt syntax
Gültige Fälle
js
const a = BigInt("1");
const b = BigInt(" 1 ");
const c = BigInt.asIntN(4, "8");