The Wayback Machine - https://web.archive.org/web/20241231234121/https://www.geeksforgeeks.org/javascript-syntaxerror-missing-formal-parameter/
Open In App

JavaScript SyntaxError – Missing formal parameter

Last Updated : 16 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

Case 1: Incorrect Function Syntax

Error Cause:

A common cause is incorrect function syntax, such as using a comma without a following parameter name.

Example:

function exampleFunction(a, , b) {
return a + b;
}
console.log(exampleFunction(1, 2));

Output:

SyntaxError: Missing formal parameter

Resolution of Error:

Ensure that all parameters are correctly defined and separated by commas.

JavaScript
function exampleFunction(a, b) {
    return a + b;
}
console.log(exampleFunction(1, 2)); // Correct usage

Output
3

Case 2: Arrow Function with Missing Parameter

Error Cause:

An arrow function with missing parameters can also cause this error.

Example:

const exampleFunction = (a, , b) => a + b;
console.log(exampleFunction(1, 2));

Output:

SyntaxError: Missing formal parameter

Resolution of Error:

Ensure that all parameters are correctly defined.

JavaScript
const exampleFunction = (a, b) => a + b;
console.log(exampleFunction(1, 2)); // Correct usage

Output
3

Case 3: Function Constructor with Missing Parameter

Error Cause:

Using the Function constructor with incorrect parameters can lead to this error.

Example:

const exampleFunction = new Function('a', '', 'b', 'return a + b');
console.log(exampleFunction(1, 2));

Output:

SyntaxError: Missing formal parameter

Resolution of Error:

Ensure that all parameters are correctly defined in the Function constructor.

JavaScript
const exampleFunction = new Function('a', 'b', 'return a + b');
console.log(exampleFunction(1, 2)); // Correct usage

Output
3



Next Article

Similar Reads

three90RightbarBannerImg