Answer
JavaScript is used to write programmable behavior in web pages and other host environments.
• In browsers it handles events, updates documents, and communicates over networks through web APIs.
• The language can also power servers, tools, and applications in suitable runtimes.
• Available capabilities depend on the host environment, not ECMAScript alone.
Example
Code
document.querySelector('button')?.addEventListener('click', () => {
console.log('Clicked');
});Output
Clicked
Quick Revision
JavaScript provides program logic while hosts provide APIs such as the DOM.