What JavaScript adds to a web page
HTML describes a document, CSS controls its presentation, and JavaScript handles behavior and computation. A button can update a score, a form can explain invalid input, and a page can request new data without a full reload. JavaScript is a separate language from Java.
Language versus browser APIs
Variables, functions, arrays and promises belong to the language. document, DOM events and localStorage are APIs provided by a browser environment. A JavaScript runtime outside the browser may not provide document. This course begins in the browser so you can see both console output and page changes.
First interactive page
Ready.
Save this fragment inside an HTML body's document and open it in a browser. Initially the paragraph says Ready. Activating the button changes it to the greeting. The script appears after the elements, so the selections find nodes that already exist. The button also works with keyboard activation.
Read the execution sequence
- The browser parses the button and paragraph.
- The script selects references to those elements.
- addEventListener registers a function; it does not run that function immediately.
- A later click invokes the function and updates the paragraph.
Practice and self-check
Change the greeting, add a second button that restores Ready, and test using Tab then Enter. If the page does not change, open the console and read the first error. A null selection often indicates an incorrect ID or code running before the element exists.
Question: Does changing text in the browser automatically update a database? Answer: No. Persistence requires a separate storage or server operation. हिन्दी संकेत: browser में दिखने वाला बदलाव और server पर saved data अलग चीजें हैं।