DEV Community

Saravanan s
Saravanan s

Posted on

JAVA script

Understanding Hoisting and addEventListener in JavaScript

       JavaScript is one of the most popular programming languages, but sometimes its behavior can feel confusing to beginners
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.).
Enter fullscreen mode Exit fullscreen mode

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)