JavaScript Output
JavaScript has several ways to display output: writing to the browser console, writing into the HTML document, showing alert boxes, or writing to the browser window.
For development and debugging, `console.log()` is by far the most common tool. It prints values to the browser's developer console without disturbing the page.
console.log
console.log() is the developer's best friend โ it prints any value, including objects and arrays, to the console for inspection.
Other output methods
`document.write()` writes into the HTML document (rarely used today), `alert()` shows a popup box, and `innerHTML` changes page content directly.
console.log("Debug info", 42, true);Debug info 42 trueconsole.log accepts multiple comma-separated arguments.
document.getElementById("demo").innerHTML = "Hello!";innerHTML changes the content of an HTML element.
Key points
- console.log() prints to the developer console.
- innerHTML changes the content of a page element.
- alert() shows a blocking popup dialog.
- document.write() is legacy and rarely used in modern code.
