Last active
March 26, 2020 11:42
-
-
Save tarun-nagpal-github/c383e7694abe14daef4c018e8bf52eb9 to your computer and use it in GitHub Desktop.
JavaScript - Interview Puzzles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What is the output and Why | |
const myData = [1,2,3,4]; | |
console.log(myData[4]); | |
// Answer - undefined | |
// What is the code below doing and how we can optimize it | |
const items = document.querySelctorAll('#container > div'); | |
items.forEach(el => { | |
el.addEventListener('click', () => { | |
console.log('Event Clicked'); | |
}); | |
}); | |
// Answer - https://javascript.info/event-delegation | |
// Question - What will happen when we register 2 click events on 1 button | |
// Why the two this has diffrent values | |
var hello = document.getElementById("myId"); | |
hello.addEventListener("click", () => { | |
console.log(this); | |
}); | |
hello.addEventListener("click", myFunction); | |
function myFunction(){ | |
console.log("HELLO WORLD 3"); | |
console.log(this); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment