General Trivia Flashcards
What’s the difference between stopPropagation and preventDefault?
stopPropagation prevents further propagation of the current event in the capturing and bubbling phases.
preventDefault prevents the default action the browser makes on that event.
What does stopImmediatePropagation do?
stopImmediatePropagation() method of the Event interface prevents other listeners of the same event from being called.
If several listeners are attached to the same element for the same event type, they are called in the order in which they were added. If stopImmediatePropagation() is invoked during one such call, no remaining listeners will be called.
document.getElementsByTagName vs. document.querySelector()
The getElementsByTagName method of Document interface returns an HTMLCollection of elements with the given tag name.
The Document method querySelector() returns the first Element within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned.
What kinds of operations result in O(1) time?
Assignment operator (printing, returning, comparing), mathematics, any fixed string, even if you're iterating through the string, because it's fixed and strings are immutable in JS.
What results in an O(n) time?
Iterating through arrays, the time it takes to go through the array is the amount of time (proportional) to go through the whole array.
What results in an O(n^2) time?
Usually nested loops, BUT not always!