Question 6
Back to Exercise
The page contains this HTML:
<input id="q" value="old">What does the following JavaScript code print when it runs on this page?
const q = document.getElementById("q");
q.value = "new";
console.log(q.value, q.getAttribute("value"), q.defaultValue);
- A new new new
- B old old old
- C new new old
- D new old old Correct
Correct Answer: Option D
Setting the property changes the live value only; the attribute (and defaultValue, which reflects it) stays "old".
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!