Outputs in JavaScript (OCR A-Level Computer Science): Revision Notes
📚 Revision Notes
Outputs in JavaScript
Overview
Outputs in JavaScript are used to display information to the user, often through alerts, HTML elements, or the browser console. Understanding output methods is essential for debugging and user interactions.
Key Concepts
- console.log(): Outputs information to the browser's console.
- alert(): Displays a pop-up message.
- document.write() and innerHTML*: Writes output directly to the HTML document or element.
lightbulbExample
Example Code
console.log("This is a console message.");
alert("Welcome to the page!");
document.getElementById("output").innerHTML = "Hello, user!";
Common Mistakes
- Misusing document.write(): It overwrites the document, so it should be used sparingly.
infoNote
Key Takeaways
- Choose appropriate output methods depending on whether you're debugging (console.log()) or interacting with users (alert()).