JavaScript SyntaxError - A declaration in the head of a for-of loop can't have an initializer Last Updated : 31 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report This JavaScript exception a declaration in the head of a for-of loop can't have an initializer occurs if the for -of loop contains an initialization expression like |for (var i = 0 of iterable)|. This is not valid initialization in for-of loops. Message: SyntaxError: for-of loop head declarations cannot have an initializer (Edge) SyntaxError: a declaration in the head of a for-of loop can't have an initializer (Firefox) SyntaxError: for-of loop variable declaration may not have an initializer. (Chrome) Error Type: SyntaxError Cause of Error: The loop contains an initialization that is invalid inside for-of loops. Example 1: HTML <!DOCTYPE html> <html> <head> <title>Syntax Error</title> </head> <body> <script> let iter = [10, 20, 30]; for (let val of iter) { document.write(val + "<br>"); } </script> </body> </html> Output: 10 20 30 Example 2: This example contains an invalid initialization inside the head of for-of the loop. HTML <!DOCTYPE html> <html> <head> <title>Syntax Error</title> </head> <body> <script> let iter = [10, 20, 30]; for (let val = 10 of iter) { document.write(val + "<br>"); } </script> </body> </html> Output(in console): SyntaxError: for-of loop variable declaration may not have an initializer. Comment More infoAdvertise with us Next Article JavaScript for...in loop not working - Object property is not defined Error P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-basics Similar Reads JavaScript ReferenceError - Can't access lexical declaration`variable' before initialization This 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 How to fix SyntaxError â Private field '#x' must be declared in an enclosing class in JavaScript? In JavaScript "SyntaxError : Private field '#x' must be declared in an enclosing class" error occurs when code tries to access or use a private field that has not been declared within the class it is being used, private fields in JavaScript are declared using a # prefix and can only be accessed with 4 min read JavaScript SyntaxError - Missing = in const declaration 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 declarat 1 min read How to Fix SyntaxError: arguments is not valid in Fields in JavaScript? A Syntax Error argument is not valid in fields occurs in JavaScript when the arguments object is used improperly within the context of a class field or similar construct where it's not allowed, the arguments object is an array-like object accessible within the scope of a function that contains the v 3 min read JavaScript for...in loop not working - Object property is not defined Error A for...in loop is a special loop in JavaScript that enumerates all the keys (object property names) of an object. With each new iteration, a new property string is assigned to the loop variable. Error: Uncaught ReferenceError: Object property is not defined If we try to compare this loop variable w 3 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 Like