LearnFrenzy
Sign in Take a free test

Functions · Find the Error · Question 5

Error: "use strict" in a function with defaults Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

JavaScript refuses to run the code below. Which statement correctly describes the problem?

main.js
function connect(host = "localhost", port = 3306) {
  "use strict";
  return `${host}:${port}`;
}
console.log(connect());
  • A It prints localhost:3306
  • B It prints undefined:undefined
  • C ReferenceError: host is not defined
  • D SyntaxError: a function with default, rest or destructured parameters cannot contain a "use strict" directive Correct
Correct Answer: Option D

"Illegal 'use strict' directive in function with non-simple parameter list". Put "use strict" at the top of the file (or use a module, which is always strict).

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links