Why is JavaScript event-driven?
First, it is useful to gain an understanding of what “event-driven” means. In event-driven architecture, the program builds off a pattern known as publish-subscribe or observer. In this pattern, there is a “subject” who broadcasts a message to at least one “observer.” The way that this applies to JavaScript is that JavaScript in your browser interacts with HTML elements, where the HTML takes on the role of subject, and JavaScript functions taking on the role of the observer. However, it is not every JavaScript function that is the “listener” to the HTML “event emitter.” JavaScript functions have to be registered as a listener with .addEventListener. This capability to interact makes JavaScript event-driven.
Leave a Reply
You must be logged in to post a comment.