Categories
JavaScript Answers

How to Fix the ‘SyntaxError: missing formal parameter ‘ Error in Our JavaScript App?

Spread the love

Sometimes, we may run into the ‘SyntaxError: missing formal parameter’ when we’re developing JavaScript apps.

In this article, we’ll look at how to fix the ‘SyntaxError: missing formal parameter’ when we’re developing JavaScript apps.

Fix the ‘SyntaxError: missing formal parameter’ When Developing JavaScript Apps

To fix the ‘SyntaxError: missing formal parameter’ when we’re developing JavaScript apps, we should make sure that our function signatures have expressions that are valid parameters.

For instance, the following code will all throw this error:

function square(3) {
  return number * number;
};

function greet("Howdy") {
  return greeting;
};

function log({ obj: "value"}) {
  console.log(arg)
};

The first function has a number instead of a variable as a parameter.

The 2nd function has a string literal instead of a variable as a parameter.

The last function has an object literal instead of a variable as a parameter.

To fix them, we write:

function square(number) {
  return number * number;
};

function greet(greeting) {
  return greeting;
};

function log(arg) {
  console.log(arg)
};

which all have variables as parameters.

Conclusion

To fix the ‘SyntaxError: missing formal parameter’ when we’re developing JavaScript apps, we should make sure that our function signatures have expressions that are valid parameters.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *