Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript SyntaxError – “use strict” not allowed in function with non-simple parameters

  • Last Updated : 31 Jul, 2020

This JavaScript exception ‘use strict’ not allowed in function occurs if strict modes ‘use strict’ statement is used at the beginning of a function with default parameters, rest parameters, or destructuring parameters.

Message:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Edge: Cannot apply strict mode on functions 
      with non-simple parameter list
Firefox:
SyntaxError: "use strict" not allowed in function 
              with default parameter
SyntaxError: "use strict" not allowed in function 
              with rest parameter
SyntaxError: "use strict" not allowed in function
              with destructuring parameter
Chrome:
SyntaxError: Illegal 'use strict' directive in function 
             with non-simple parameter list

Error Type:

SyntaxError

Cause of Error: A strict modes “use strict” is written at the start of a function that has the Default, Rest, or Destructing Parameters.



Example 1: In this example, the default parameter is not used, So the error has not occurred.

HTML




<script
  function GFG(a, b) {
            'use strict';
            return a + b;
    
  document.write(GFG(2, 5)); 
</script>

Output:

7

Example 2: In this example, the default parameter is used, So the error has occurred.

HTML




<script
  function GFG(a=2, b=3) {
            'use strict';
            return a + b;
    
  document.write(GFG(2, 5)); 
</script>

Output(In console):

SyntaxError: Illegal 'use strict' directive in
function with non-simple parameter list
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!