Question 5
Back to Exercise
The page contains this HTML:
<div id="u" data-user-id="42" data-is-admin="false"></div>What does the following JavaScript code print when it runs on this page?
const { userId, isAdmin } = document.getElementById("u").dataset;
console.log(userId + 1, typeof userId, isAdmin ? "admin" : "user");
- A 43 number user
- B 421 string admin Correct
- C 421 string user
- D 43 string admin
Correct Answer: Option B
dataset values are always strings: "42" + 1 is "421", and the non-empty string "false" is truthy.
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!