Question 2
Back to Exercise
The page contains this HTML:
<div id="profile"></div>JavaScript refuses to run the code below. Which statement correctly describes the problem?
const profile = document.getElementById("profile");
profile.dataset.user-id = "42";
- A It sets data-user-id="42"
- B It sets data-user="42"
- C ReferenceError: id is not defined
- D SyntaxError: it parses as profile.dataset.user - id = "42", an invalid assignment target – use dataset.userId Correct
Correct Answer: Option D
dataset uses camelCase (dataset.userId) or bracket notation with the camelCase key. A subtraction cannot be assigned to.
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!