Window.alert() and console.log()-tutorial
JavaScript offers different ways to display output depending on your need:
- to show messages to users
- or to debug your code in the console.
window.alert()
The window.alert() method displays an alert box with a custom message and an OK button.
Key point
- Forces users to see the message before interacting with the page.
- Best for warnings, confirmations, or quick notices.
Syntax:
window.alert("Your message here");
Example:
<!DOCTYPE html><html>
<body> <h1>Quipoin</h1> <script> window.alert("This is Quipoin.com"); </script></body>
</html>
Output
.webp)
console.log()
The console.log() method writes messages to the browser's console.
It is mainly used for debugging - helping developers check variable values, calculations, or program flow.
Example:
Example:
<!DOCTYPE html><html>
<body> <h2>Activate Debugging</h2> <p>Press F12 to open the developer console.</p> <p>Then select "Console" and reload or run the code again.</p>
<script> console.log(5 + 6); </script></body>
</html>
Output
.webp)