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

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:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

7

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

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output(In console):

SyntaxError: Illegal 'use strict' directive in
function with non-simple parameter list

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.