JavaScript SyntaxError – Missing formal parameter

This JavaScript exception missing formal parameter occurs if any function declaration doesn’t have the valid parameters.

Message:

SyntaxError: missing formal parameter (Firefox)

Error Type:

SyntaxError

Cause of Error: The function declaration is missing the formal parameters.

Example 1: In this example, the parameter ‘num’ is not defined in the list of formal parameters, So the error has occurred.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
    function cube(5) {
      return num * num * num;
    }
    </script>
</body>
</html>


Output(In Firefox console):

SyntaxError: missing formal parameter

Example 2: In this example, the parameter ‘w3wiki’ is not defined in a list of formal parameters, So the error has occurred.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
    function GFG("Geek") {
      return w3wiki;
    };
    </script>
</body>
</html>


Output(In Firefox console):

SyntaxError: missing formal parameter


Contact Us