Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript SyntaxError – Missing name after . operator

Improve Article
Save Article
Like Article
  • Last Updated : 24 Jul, 2020
Improve Article
Save Article
Like Article

This 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 provide the name of the properties to access. Somewhere the dot operator is used with the square bracket or “+” is used with dot operator, Both causes the problems.

Example 1: In this example, the property is accessed with the dot operator along with a square bracket, so the error has occurred.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
    var GFG_Obj = {
      prop: 
       
        prop1: "val1", 
        prop2: "val2" 
       }
    };
    document.write(GFG_Obj.[prop].[prop1]);
    </script>
</body>
</html>

Output(In console):

SyntaxError: missing name after . operator

Example 2: In this example, the property is accessed with the dot operator along with “+”(concatenation), so the error has occurred.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
    var GFG_Obj = {
      prop: 
       
        prop1: "val1", 
        prop2: "val2" 
       }
    };
    var k = 2;
    document.write(GFG_Obj.prop."prop" + k);
    </script>
</body>
</html>

Output(In console):

SyntaxError: missing name after . operator

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!