JS Questions Flashcards
Explain event delegation.
Event Delegation is a pattern based upon the concept of Event Bubbling. It is an event-handling pattern that allows you to handle events at a higher level in the DOM tree other than the level where the event was first received.
EX: Click Me! button. Due to event bubbling, when the button receives an event, say click, that event bubbles up the tree, so span and div will respectively receive the event also.
const div = document.getElementsByTagName(“div”)[0]
div.addEventListener(“click”, (event) => {
if(event.target.tagName === ‘BUTTON’) {
console.log(“button was clicked”)
}
})
Explain how prototypal inheritance works.
What’s the difference between a variable that is: null, undefined or undeclared?
How would you go about checking for any of these states?
What is a closure, and how/why would you use one?
What language constructions do you use for iterating over object properties and array items?
Can you describe the main difference between the Array.forEach() loop and Array.map() methods and why you would pick one versus the other?
What’s a typical use case for anonymous functions?
What’s the difference between host objects and native objects?
Explain the difference between: function Person(){}, var person = Person(), and var person = new Person()?
Explain the differences on the usage of foo between function foo() {} and var foo = function() {}
Can you explain what Function.call and Function.apply do? What’s the notable difference between the two?
Explain Function.prototype.bind.
What’s the difference between feature detection, feature inference, and using the UA string?
Explain “hoisting”.
Describe event bubbling.
Describe event capturing.
What’s the difference between an “attribute” and a “property”?
What are the pros and cons of extending built-in JavaScript objects?
What is the difference between == and ===?
Explain the same-origin policy with regards to JavaScript.
Why is it called a Ternary operator, what does the word “Ternary” indicate?
What is strict mode? What are some of the advantages/disadvantages of using it?
What are some of the advantages/disadvantages of writing JavaScript code in a language that compiles to JavaScript?
What tools and techniques do you use debugging JavaScript code?
Explain the difference between mutable and immutable objects.
What is an example of an immutable object in JavaScript?