JavaScript SyntaxError - A declaration in the head of a for-of loop can't have an initializer Last Updated : 31 Jul, 2020 Comments Improve Suggest changes 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 SyntaxError - A declaration in the head of a for-of loop can't have an initializer 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 JavaScript SyntaxError - Missing } after property list This 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 TypeError - 'X' is not iterable This 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 SyntaxError - Unexpected token This JavaScript exceptions unexpected token occur if a specific language construct was expected, but anything else is typed mistakenly. This could be a simple typing mistake. Message: SyntaxError: expected expression, got "x" SyntaxError: expected property name, got "x" SyntaxError: expected target, 1 min read Explain the different variants of for loop in TypeScript Loops are used to execute a specific block of code a specific number of times. There are 2 types of loops in TypeScript which are Definite Loop (for), and Indefinite Loops (while, do..while) In TypeScript, we have basically 3 kinds of for loops. forfor .. offor .. in for loop: The for loop is used t 4 min read Like