Understanding Hoisting and addEventListener in JavaScript
JavaScript is one of the most popular programming languages, but sometimes its behavior can feel confusing to beginners
What is Hoisting in JavaScript
Hoisting is a default behavior in JavaScript where variable and function declarations are moved (“hoisted”) to the top of their scope before the code is executed.
sayHello(); // ✅ Works, even though the function is defined later
function sayHello() {
console.log("Hello, I was hoisted!");
}
What is addEventListener().
web development, we often need to make our websites interactive. That’s where events come in (like clicks, key presses, mouse moves, etc.).
The method addEventListener() is used to attach an event handler to an element.
element.addEventListener(event, function, useCapture);
This the hosited and addevebtlisnter
Top comments (0)