Careeroza
Output
Ways to Display Output
| Method | Shows output in |
|---|---|
console.log() | the browser console (F12) or terminal: for debugging |
element.textContent = ... | an HTML element: for users |
alert() | a pop-up box (blocks the page; avoid in real apps) |
document.write() | the document while loading (never use after load) |
console.log
Example
console.log accepts any number of values, and objects are shown in full:
const name = "Asha";
const scores = [92, 87, 95];
console.log("Name:", name);
console.log("Scores:", scores);
console.log({ name, total: 274 });
console.table([{ subject: "HTML", marks: 92 }, { subject: "CSS", marks: 87 }]);Output
Name: Asha
Scores: [ 92, 87, 95 ]
{ name: 'Asha', total: 274 }
┌─────────┬─────────┬───────┐
│ (index) │ subject │ marks │
├─────────┼─────────┼───────┤
│ 0 │ 'HTML' │ 92 │
│ 1 │ 'CSS' │ 87 │
└─────────┴─────────┴───────┘Writing into the Page
Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p id="out"></p>
<script>
const price = 499;
document.getElementById("out").textContent = "Total with 18% GST: ₹" + (price * 1.18).toFixed(2);
</script>
</body>
</html>Result