LearnFrenzy
Sign in Take a free test

Objects · Find the Error · Question 2

Error: mixing method and arrow syntax Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

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

main.js
const greeter = {
  greet() => "Hello",
};
console.log(greeter.greet());
  • A It prints Hello
  • B TypeError: greet is not a function
  • C It prints undefined
  • D SyntaxError: write either greet() { return "Hello"; } or greet: () => "Hello", not a mix of both Correct
Correct Answer: Option D

Method shorthand needs a body in braces; an arrow function must be the value of a key: greet: () => "Hello".

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