Web Development MCQs

100 MCQs  (Page 5 of 10)

With const obj = {a: 1};, what happens with obj.a = 2;?
TypeError
It works; const prevents reassigning the variable, not mutating the object
SyntaxError
obj becomes undefined
What does this log? const obj = { name: 'PMD', show: () => console.log(this.name) }; obj.show();
PMD
ReferenceError
obj
undefined (in a browser module or script, this is not obj)
What is the difference between event.preventDefault() and event.stopPropagation()?
stopPropagation cancels form submission
preventDefault stops the browser's default action (such as following a link); stopPropagation stops the event bubbling to ancestor elements
They are identical
preventDefault stops bubbling
In which phase do event listeners run by default with addEventListener?
Both phases
Neither, until enabled
The capturing phase
The bubbling phase