JavaScript can show output (results or messages) in many ways. The most common methods are:
1. `innerHTML` – Displays output inside an HTML element.
```html
document.getElementById("demo").innerHTML = "Hello JavaScript!";
```
It is used to change content on a webpage directly.
2. `document.write()` – Writes output directly to the HTML page.
```html
document.write("Welcome!");
```
It is mostly used for testing because it can erase the page after loading.
3. *`alert()* – Displays a popup message box.
```html
alert("This is an alert box!");
```
Useful for showing simple messages.
4. *console.log()`* – Shows output in the browser console (for debugging).
```html
console.log("This is a log message");
```
5. *`window.print()`* – Opens the print dialog for the webpage.
```html
window.print();
```
Each method serves a different purpose — for example, `console.log()` is great for developers, while `innerHTML` changes what users see on the screen.
Enjoy! Follow us for more...

No comments:
Post a Comment