Missing formal parameter
JavaScript Programming Language
Severity: MinorWhat Does This Error Mean?
Missing formal parameter is a SyntaxError that means your function definition has something wrong in the parameter list — the part inside the parentheses after the function name. JavaScript expected a valid parameter name but found something else, like a number, a string, or an expression. For example: function add(1, 2) {} is invalid — parameter names must be identifiers (variable names), not values.
Affected Models
- All browsers
- Node.js
- All JavaScript environments
Common Causes
- Using a number or literal value as a parameter name: function add(1, 2) — parameter names must be variable names, not values
- A syntax mistake in the function declaration leaves the parameter list malformed
- Using a reserved word as a parameter name in strict mode
- Passing arguments when declaring a function instead of when calling it
- A missing or extra comma, bracket, or parenthesis near the function definition
How to Fix It
-
Find the function definition that caused the error. The browser console shows the file and line number.
Look at the part inside the parentheses — those are the parameters. They must all be valid JavaScript identifiers (letters, $, _, digits — but not starting with a digit).
-
Make sure you are using names (identifiers) for parameters, not values. function greet(name) is correct. function greet('Alice') is wrong.
The parameter names are placeholders — they get replaced by the actual values when the function is called. Define: function add(a, b). Call: add(1, 2).
-
Check for syntax mistakes like missing commas between parameters, extra brackets, or unclosed parentheses near the function definition.
Example: function add(a b) is missing the comma — it should be function add(a, b).
-
Make sure you are not using a JavaScript reserved word as a parameter name. Words like 'return', 'class', 'if', 'for', 'let', 'const' are reserved and cannot be parameter names.
If you accidentally write function doSomething(return) — that is invalid because return is a reserved word.
-
If using destructuring in function parameters, make sure the syntax is correct: function greet({name, age}) is valid. function greet({name age}) is not — there must be a comma.
Destructuring in parameters is powerful but the syntax must be exact — treat it like an object literal.
When to Call a Professional
Missing formal parameter is a syntax mistake — the code cannot run at all until it is fixed. Carefully re-read your function definition and fix the parameter list. Parameters are just names you give to the inputs — they should be simple variable names like x, name, or userAge.
Frequently Asked Questions
What is a formal parameter?
A formal parameter is the name given to an input in a function definition. In function add(a, b), the formal parameters are 'a' and 'b'. When you call add(5, 3), the values 5 and 3 are the arguments — they get assigned to the parameters a and b inside the function. Formal parameters must be valid variable names.
What is the difference between a parameter and an argument?
A parameter is the name in the function definition: function greet(name) — name is a parameter. An argument is the actual value you pass when calling the function: greet('Alice') — 'Alice' is an argument. The two words are often used interchangeably in everyday conversation, but technically they are different.
Can I use default values for parameters in JavaScript?
Yes — modern JavaScript lets you specify default values: function greet(name = 'World') { return 'Hello, ' + name; } If you call greet() without an argument, name defaults to 'World'. If you call greet('Alice'), name is 'Alice'. Default values are set with = in the parameter list.