Heres an example of how to subscribe to an event in JavaScript: const button = document.querySelector('#my-button'); button.addEventListener('click', function() { console.log('Button was clicked!'); }); for the example, we are adding an event listener to the button element. The event listener function will be called whenever the button is clicked. you can also use the subscribe method from a library like RxJS to subscribe to an observable. Here is an example: import { fromEvent } from 'rxjs'; import { take } from 'rxjs/operators'; const button = document.querySelector('#my-button'); fromEvent(button, 'click').pipe(take(1)).subscribe(console.log);