Categories
JavaScript Answers

How to Fix the ‘SyntaxError: “use strict” not allowed in function with non-simple parameters ‘ Error in Our JavaScript App?

Spread the love

Sometimes, we may run into the ‘SyntaxError: "use strict" not allowed in function with non-simple parameters’ when we’re developing JavaScript apps.

In this article, we’ll look at how to fix the ‘SyntaxError: "use strict" not allowed in function with non-simple parameters’ when we’re developing JavaScript apps.

Fix the ‘SyntaxError: "use strict" not allowed in function with non-simple parameters’ When Developing JavaScript Apps

To fix the ‘SyntaxError: "use strict" not allowed in function with non-simple parameters’ when we’re developing JavaScript apps, we should make sure we don’t add the 'use strict' directive inside a function that uses default parameters, rest parameters, or destructuring parameters.

In Edge, the error message for this error is Cannot apply strict mode on functions with non-simple parameter list .

In Firefox, the error message for this error is SyntaxError: "use strict" not allowed in function with default parameter, SyntaxError: "use strict" not allowed in function with rest parameter, and SyntaxError: "use strict" not allowed in function with destructuring parameter.

And in Chrome, the error message for this error is SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list.

For instance, we shouldn’t write code like:

const sum = (a = 1, b = 2) => {
  'use strict';
  return a + b;
}

Instead, we should put 'use strict' before the function:

"use strict";
const sum = (a = 1, b = 2) => {
  return a + b;
};

Conclusion

To fix the ‘SyntaxError: "use strict" not allowed in function with non-simple parameters’ when we’re developing JavaScript apps, we should make sure we don’t add the 'use strict' directive inside a function that uses default parameters, rest parameters, or destructuring parameters.

In Edge, the error message for this error is Cannot apply strict mode on functions with non-simple parameter list .

In Firefox, the error message for this error is SyntaxError: "use strict" not allowed in function with default parameter, SyntaxError: "use strict" not allowed in function with rest parameter, and SyntaxError: "use strict" not allowed in function with destructuring parameter.

And in Chrome, the error message for this error is SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list.

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 *