JavaScript SyntaxError - Missing = in const declaration Last Updated : 27 Sep, 2021 Comments Improve Suggest changes Like Article Like Report This JavaScript exception missing = in const declaration occurs if a const is declared and value is not provided(like const ABC_DEF;). Need to provide the value in same statement (const ABC_DEF = '#ee0'). Message: SyntaxError: Const must be initialized (Edge) SyntaxError: missing = in const declaration (Firefox) SyntaxError: Missing initializer in const declaration (Chrome) Error Type: SyntaxError Cause of Error: A constant value cannot be changed by the program while execution. It cannot be altered through re-assignment also. Example 1: In this example, a const is declared but not initialized so the error has occurred. HTML <!DOCTYPE html> <html> <head> <title>Syntax Error</title> </head> <body> <script> const GFG; document.write(GFG); </script> </body> </html> Output: SyntaxError: Const must be initialized Example 2: In this example, a const is declared and initialized later, so the error has occurred. HTML <!DOCTYPE html> <html> <head> <title>Syntax Error</title> </head> <body> <script> const INIT_VAL; // invalid statement INIT_VAL = 5; document.write(INIT_VAL); </script> </body> </html> Output: SyntaxError: Const must be initialized Comment More infoAdvertise with us Next Article JavaScript SyntaxError - Missing name after . operator P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Errors Similar Reads JavaScript Error Object Complete Reference Error objects are arising at runtime errors. The error object also uses as the base object for the exceptions defined by the user. The complete list of JavaScript Error Object properties are listed below: Error types JavaScript RangeError â Invalid dateJavaScript RangeError â Repeat count must be no 3 min read JS Range ErrorJavaScript RangeError - Invalid dateThis JavaScript exception invalid date occurs if the string that has been provided to Date or Date.parse() is not valid.Message:RangeError: invalid date (Edge)RangeError: invalid date (Firefox)RangeError: invalid time value (Chrome)RangeError: Provided date is not in valid range (Chrome)Error Type:R 2 min read JavaScript RangeError - Repeat count must be non-negativeThis JavaScript exception repeat count must be non-negative occurs if the argument passed to String.prototype.repeat() method is a negative number. Message: RangeError: argument out of range RangeError: repeat count must be non-negative (Firefox) RangeError: Invalid count value (Chrome) Error Type: 1 min read JS Reference ErrorJavaScript ReferenceError - Can't access lexical declaration`variable' before initializationThis JavaScript exception can't access the lexical declaration `variable' before initialization occurs if a lexical variable has been accessed before initialization. This could happen inside any block statement when let or const declarations are accessed when they are undefined. Message: ReferenceEr 2 min read JavaScript ReferenceError - Invalid assignment left-hand sideThis JavaScript exception invalid assignment left-hand side occurs if there is a wrong assignment somewhere in code. A single â=â sign instead of â==â or â===â is an Invalid assignment. Message: ReferenceError: invalid assignment left-hand side Error Type: ReferenceError Cause of the error: There ma 2 min read JavaScript ReferenceError - Assignment to undeclared variableThis JavaScript exception Assignment to undeclared variable occurs in strict-mode If the value has been assigned to an undeclared variable. Message: ReferenceError: assignment to undeclared variable "x" (Firefox) ReferenceError: "x" is not defined (Chrome) ReferenceError: Variable undefined in stric 2 min read JavaScript ReferenceError - Reference to undefined property "x"This JavaScript warning reference to undefined property occurs if a script tries to access an object property that doesn't exist.Message:ReferenceError: reference to undefined property "x" (Firefox)Error Type:ReferenceError(Only reported by firefox browser)Cause of the error: The script is trying to 2 min read JavaScript ReferenceError - variable is not definedThis JavaScript exception variable is not defined and occurs if there is a non-existent variable that is referenced somewhere. Message: ReferenceError: "x" is not defined Error Type: ReferenceError Cause of Error: There is a non-existent variable that is referenced somewhere in the script. That vari 1 min read JavaScript ReferenceError Deprecated caller or arguments usageThis JavaScript exception deprecated caller or arguments usage occurs only in strict mode. It occurs if any of the Function.caller or Function.arguments properties are used, Which are depreciated. Message: TypeError: 'arguments', 'callee' and 'caller' are restricted function properties and cannot be 1 min read JS Syntax ErrorJavaScript SyntaxError - Illegal characterThis JavaScript exception illegal character occurs if there is an invalid or unexpected token that doesn't belong there in the code.Understanding an errorAn "Unexpected token ILLEGAL" error signifies that there is an invalid character present within the code, in certain situations, JavaScript requir 2 min read JavaScript SyntaxError - Identifier starts immediately after numeric literalThis JavaScript exception identifier starts immediately after a numeric literal occurs if an identifier starts with a number. Message: SyntaxError: Unexpected identifier after numeric literal (Edge) SyntaxError: identifier starts immediately after numeric literal (Firefox) SyntaxError: Unexpected nu 1 min read JavaScript SyntaxError - Function statement requires a nameThis JavaScript exception function statement requires a name that occurs if there is any function statement in the script which requires a name. Message: Syntax Error: Expected identifier (Edge) SyntaxError: function statement requires a name [Firefox] SyntaxError: Unexpected token ( [Chrome] Error 1 min read JavaScript SyntaxError - Missing } after function bodyThis JavaScript exception missing } after function body occurs if there is any syntactic mistyping while creating a function somewhere in the code. Closing curly brackets/parentheses must be incorrect order. Message: SyntaxError: Expected '}' (Edge) SyntaxError: missing } after function body (Firefo 1 min read JavaScript SyntaxError - Missing } after property listThis JavaScript exception missing } after property list occurs if there is a missing comma, or curly bracket in the object initializer syntax. Message: SyntaxError: Expected '}' (Edge) SyntaxError: missing } after property list (Firefox) Error Type: SyntaxError Cause of Error: Somewhere in the scrip 1 min read JavaScript SyntaxError - Missing variable nameThis JavaScript exception missing variable name occurs frequently If the name is missing or the comma is wrongly placed. There may be a typing mistake.Message:SyntaxError: missing variable name (Firefox)SyntaxError: Unexpected token = (Chrome)Error Type:SyntaxErrorCause of Error: There might be a va 1 min read JavaScript SyntaxError - Missing ] after element listThis JavaScript exception missing ] after element list occurs, It might be an error in array initialization syntax in code. Missing closing bracket (â]â) or a comma (â,â) also raises an error.Message:SyntaxError: missing ] after element listError Type:SyntaxErrorCause of Error: Somewhere in the scri 2 min read JavaScript SyntaxError - Invalid regular expression flag "x"This JavaScript exception invalid regular expression flag occurs if the flags, written after the second slash in RegExp literal, are not from either of (g, i, m, s, u, or y).Error Message on console:SyntaxError: Syntax error in regular expression (Edge) SyntaxError: invalid regular expression flag " 1 min read JavaScript SyntaxError "variable" is a reserved identifierThis JavaScript exception variable is a reserved identifier occurs if the reserved keywords are used as identifiers. Message: SyntaxError: The use of a future reserved word for an identifier is invalid (Edge) SyntaxError: "x" is a reserved identifier (Firefox) SyntaxError: Unexpected reserved word ( 1 min read JavaScript SyntaxError - Missing ':' after property idThis JavaScript exception missing : after property id occurs if objects are declared using the object's initialization syntax.Message:SyntaxError: Expected ':' (Edge)SyntaxError: missing : after property id (Firefox)Error Type:SyntaxErrorCause of Error: Somewhere in the code, Objects are created wit 2 min read JavaScript SyntaxError - Missing ) after conditionThis JavaScript exception missing ) after condition occurs if there is something wrong with if condition. Parenthesis should be after the if keyword.Message:SyntaxError: Expected ')' (Edge)SyntaxError: missing ) after condition (Firefox)Error Type:SyntaxErrorCause of Error: Somewhere in the code the 2 min read JavaScript SyntaxError - Missing formal parameterThis JavaScript exception missing formal parameter occurs if any function declaration doesn't have the valid parameters.Message:SyntaxError: missing formal parameter (Firefox)Error Type:SyntaxErrorCause of Error: The function declaration is missing the formal parameters.Case 1: Incorrect Function Sy 1 min read JavaScript SyntaxError - Missing ; before statementThis JavaScript exception missing ; before statement occurs if there is a semicolon (;) missing in the script. Message: SyntaxError: Expected ';' (Edge) SyntaxError: missing ; before statement (Firefox) Error Type: SyntaxError Cause of Error: Somewhere in the code, there is a missing semicolon (;). 1 min read JavaScript SyntaxError - Missing = in const declarationThis JavaScript exception missing = in const declaration occurs if a const is declared and value is not provided(like const ABC_DEF;). Need to provide the value in same statement (const ABC_DEF = '#ee0'). Message: SyntaxError: Const must be initialized (Edge) SyntaxError: missing = in const declarat 1 min read JavaScript SyntaxError - Missing name after . operatorThis JavaScript exception missing name after . operator occurs if the dot operator (.) is used in the wrong manner for property access. Message: SyntaxError: missing name after . operator Error Type: SyntaxError Cause of Error: The dot operator (.) is used to access the property. Users will have to 1 min read JavaScript SyntaxError - Redeclaration of formal parameter "x"This JavaScript exception redeclaration of formal parameter occurs if a variable name is a function parameter and also declared again inside the function body using a let assignment. Message: SyntaxError: Let/Const redeclaration (Edge) SyntaxError: redeclaration of formal parameter "x" (Firefox) Syn 1 min read JavaScript SyntaxError - Missing ) after argument listThis JavaScript exception missing ) after argument list occurs if there is an error in function calls. This could be a typing mistake, a missing operator, or an unescaped string. Message: SyntaxError: Expected ')' (Edge) SyntaxError: missing ) after argument list (Firefox) Error Type: SyntaxError Ca 1 min read JavaScript SyntaxError - Return not in functionThis JavaScript exception return (or yield) not in function occurs if a return/yield statement is written outside the body of the function.Message:SyntaxError: 'return' statement outside of function (Edge)SyntaxError: return not in function (Firefox)SyntaxError: yield not in function (Firefox)Error 2 min read JavaScript SyntaxError: Unterminated string literalThis JavaScript error unterminated string literal occurs if there is a string that is not terminated properly. String literals must be enclosed by single (') or double (") quotes.Message:SyntaxError: Unterminated string constant (Edge)SyntaxError: unterminated string literal (Firefox)Error Type:Synt 2 min read JavaScript SyntaxError - Applying the 'delete' operator to an unqualified name is deprecatedThis JavaScript exception applying the 'delete' operator to an unqualified name is deprecated works in strict mode and it occurs if variables are tried to be deleted with the delete operator. Message: SyntaxError: Calling delete on expression not allowed in strict mode (Edge) SyntaxError: applying t 1 min read JavaScript SyntaxError - Using //@ to indicate sourceURL pragmas is deprecated. Use //# insteadThis JavaScript warning Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead occurs if there is a source map syntax defined in a JavaScript source, Which has been depreciated. Message: Warning: SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead War 1 min read JavaScript SyntaxError - Malformed formal parameterThis JavaScript exception malformed formal parameter occurs if the argument list of a Function() constructor call is not valid.Message:SyntaxError: Expected {x} (Edge)SyntaxError: malformed formal parameter (Firefox)Error Type:SyntaxErrorCause of Error: The argument list passed to the function is no 2 min read JavaScript SyntaxError - "0"-prefixed octal literals and octal escape sequences are deprecatedThis JavaScript exception 0-prefixed octal literals and octal escape sequences are deprecated works in strict mode only. For octal literals, the "0o" prefix can be used instead. Message: SyntaxError: Octal numeric literals and escape characters not allowed in strict mode (Edge) SyntaxError: "0"-pref 1 min read JavaScript SyntaxError - Test for equality (==) mistyped as assignment (=)?This JavaScript warning test for equality (==) is mistyped as an assignment (=)? occurs if by assignment (=) is used in place of equality (==). Message: Warning: SyntaxError: test for equality (==) mistyped as assignment (=)? Error Type: SyntaxError: Warning which is reported only if javascript.opti 1 min read JavaScript SyntaxError - "x" is not a legal ECMA-262 octal constantThis JavaScript warning 08 (or 09) is not a legal ECMA-262 octal constant that occurs if the literals 08 or 09 are used as a number. This occurs because these literals cannot be treated as an octal number. Message: Warning: SyntaxError: 08 is not a legal ECMA-262 octal constant. Warning: SyntaxError 1 min read JS Type ErrorJavaScript TypeError - "X" is not a non-null objectThis JavaScript exception is not a non-null object that occurs if an object is not passed where it is expected. So the null is passed which is not an object and it will not work. Message: TypeError: Invalid descriptor for property {x} (Edge) TypeError: "x" is not a non-null object (Firefox) TypeErro 1 min read JavaScript TypeError - "X" is not a constructorThis JavaScript exception is not a constructor that occurs if the code tries to use an object or a variable as a constructor, which is not a constructor. Message: TypeError: Object doesn't support this action (Edge) TypeError: "x" is not a constructor TypeError: Math is not a constructor TypeError: 1 min read JavaScript TypeError - "X" has no propertiesThis JavaScript exception null (or undefined) has no properties that occur if there is an attempt to access properties of null and undefined. They don't have any such properties. Message: TypeError: Unable to get property {x} of undefined or null reference (Edge) TypeError: null has no properties (F 1 min read JavaScript TypeError - "X" is (not) "Y"This JavaScript exception X is (not) Y occurs if there is a data type that is not expected there. Unexpected is undefined or null values. Message: TypeError: Unable to get property {x} of undefined or null reference (Edge) TypeError: "x" is (not) "y" (Firefox) Few example are given below: TypeError: 1 min read JavaScript TypeError - "X" is not a functionThis JavaScript exception is not a function that occurs if someone trying to call a value from a function, but in reality, the value is not a function. Message: TypeError: Object doesn't support property or method {x} (Edge) TypeError: "x" is not a function Error Type: TypeError Cause of Error: Ther 1 min read JavaScript TypeError - 'X' is not iterableThis JavaScript exception is not iterable occurs if the value present at the right-hand-side of forâ¦of or as argument of a function such as Promise.all or TypedArray.from, can not be iterated or is not an iterable object. Message: TypeError: 'x' is not iterable (Firefox, Chrome) TypeError: 'x' is no 1 min read JavaScript TypeError - More arguments neededThis JavaScript exception more arguments needed occurs if there is an error in the way of function is called. If a few arguments are provided then more arguments need to be provided. Message: TypeError: argument is not an Object and is not null (Edge) TypeError: Object.create requires at least 1 arg 1 min read JavaScript TypeError - "X" is read-onlyThis JavaScript exception is read-only works in strict mode-only and It occurs if a global variable or object property which has assigned to a value, is a read-only property. Message: TypeError: Assignment to read-only properties is not allowed in strict mode (Edge) TypeError: "x" is read-only (Fire 1 min read JavaScript TypeError - Reduce of empty array with no initial valueThis JavaScript exception reduce of empty array with no initial value occurs if a reduce function is used with the empty array. Message: TypeError: reduce of empty array with no initial value Error Type: TypeError Cause of Error: This error is raised if an empty array is provided to the reduce() met 1 min read JavaScript TypeError - Can't assign to property "X" on "Y": not an objectThis JavaScript exception can't assign to property occurs in strict-mode only and this error occurs If the user tries to create a property on any of the primitive values like a symbol, a string, a number, or a boolean. Primitive values cannot be used to hold any property. Message: TypeError: can't a 1 min read JavaScript TypeError - Can't access property "X" of "Y"This JavaScript exception can't access property occurs if property access was performed on undefined or null values. Message: TypeError: Unable to get property {x} of undefined or null reference (Edge) TypeError: can't access property {x} of {y} (Firefox) TypeError: {y} is undefined, can't access pr 1 min read JavaScript TypeError - Can't define property "X": "Obj" is not extensibleThis JavaScript exception can't define property "x": "obj" is not extensible occurs when Object.preventExtensions() is used on an object to make it no longer extensible, So now, New properties can not be added to the object. Message: TypeError: Cannot create property for a non-extensible object (Edg 1 min read JavaScript TypeError - X.prototype.y called on incompatible typeThis JavaScript exception called on incompatible target (or object)" occurs if a function (on a given object), is called with a 'this' corresponding to a different type other than the type expected by the function. Message: TypeError: 'this' is not a Set object (EdgE) TypeError: Function.prototype.t 1 min read JavaScript TypeError - Invalid assignment to const "X"This JavaScript exception invalid assignment to const occurs if a user tries to change a constant value. Const declarations in JavaScript can not be re-assigned or re-declared. Message: TypeError: invalid assignment to const "x" (Firefox) TypeError: Assignment to constant variable. (Chrome) TypeErro 1 min read JavaScript TypeError - Property "X" is non-configurable and can't be deletedThis JavaScript exception property is non-configurable and can't be deleted if the user tries to delete a property, and the property is non-configurable. Message: TypeError: Calling delete on 'x' is not allowed in strict mode (Edge) TypeError: property "x" is non-configurable and can't be deleted. ( 1 min read JavaScript TypeError - Can't redefine non-configurable property "x"This JavaScript exception can't redefine non-configurable property occurs if user tries to redefine a property, but that property is non-configurable. Message: TypeError: Cannot modify non-writable property {x} (Edge) TypeError: can't redefine non-configurable property "x" (Firefox) TypeError: Canno 1 min read JavaScript TypeError - Variable "x" redeclares argumentThis JavaScript exception variable redeclares argument occurs in strict-mode only and if the variable name which is also function parameter has been redeclared with the var keyword. Message: TypeError: variable "x" redeclares argument (Firefox) Error Type: TypeError Cause of the Error: A variable wh 1 min read JavaScript TypeError - Setting getter-only property "x"This JavaScript exception setting getter-only property works in strict-mode only and occurs if the user tries to set a new value to a property for which only a getter is specified. Message: TypeError: Assignment to read-only properties is not allowed in strict mode (Edge) TypeError: setting getter-o 2 min read JavaScript TypeError - Invalid 'instanceof' operand 'x'This JavaScript exception invalid 'instanceof' operand occurs if the right operand of the instanceof operator can not be used with a constructor object. It is an object that contains a prototype property and can be called. Message: TypeError: invalid 'instanceof' operand "x" (Firefox) TypeError: "x" 1 min read JavaScript TypeError - Invalid Array.prototype.sort argumentThis JavaScript exception invalid Array.prototype.sort argument occurs if the parameter of Array.prototype.sort() is not from either undefined or a function which sorts accordingly. Message: TypeError: argument is not a function object (Edge) TypeError: invalid Array.prototype.sort argument (Firefox 1 min read JavaScript TypeError - Cyclic object valueThis JavaScript exception cyclic object value occurs if the references of objects were found in JSON. JSON.stringify() fails to solve them. Message: TypeError: cyclic object value (Firefox) TypeError: Converting circular structure to JSON (Chrome and Opera) TypeError: Circular reference in value arg 1 min read JavaScript TypeError - Can't delete non-configurable array elementThis JavaScript exception can't delete non-configurable array element that occurs if there is an attempt to short array-length, and any one of the array's elements is non-configurable. Message: TypeError: can't delete non-configurable array element (Firefox) TypeError: Cannot delete property '2' of 1 min read JS Other ErrorsJavaScript URIError | Malformed URI SequenceThis JavaScript exception malformed URI sequence occurs if the encoding or decoding of URI is unsuccessful. Message: URIError: The URI to be encoded contains invalid character (Edge) URIError: malformed URI sequence (Firefox) URIError: URI malformed (Chrome) Error Type: URIError Cause of the Error: 1 min read JavaScript Warning - Date.prototype.toLocaleFormat is deprecatedThis JavaScript warning Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead occurs if user is using the non-standard Date.prototype.toLocaleFormat method. Message: Warning: Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead Err 1 min read Logging Script Errors in JavaScriptIn this article, we will learn to log script Errors using JavaScript. It is useful in case where scripts from any other source run/executes under the website (Ex - in an iframe) or cases where any of your viewer makes use of Browser's Console trying to alter the script or you want to monitor your JS 6 min read JS Error InstanceJavaScript Error message PropertyIn JavaScript error message property is used to set or return the error message. Syntax: errorObj.message Return Value: It returns a string, representing the details of the error. More example codes for the above property are as follows: Below is the example of the Error message property. Example 1: 1 min read JavaScript Error name PropertyIn JavaScript, the Error name property is used to set or return the name of an error. Syntax: errorObj.name Property values: This property contains six different values as described below: SyntaxError: It represents a syntax error.RangeError: It represents an error in the range.ReferenceError: It re 2 min read JavaScript Error.prototype.toString() MethodThe Error.prototype.toString() method is an inbuilt method in JavaScript that is used to return a string representing the specified Error object. Syntax: e.toString() Parameters: This method does not accept any parameters. Return value: This method returns a string representing the specified Error o 1 min read Like