10. Basic Output and Interaction
We need ways to display information or get simple input from the user.
1. console.log() (The Developer's Best Friend)
This is the most common way to display output, primarily used for debugging and viewing data internally in the browser console.
javascript let userName = 'Sam'; console.log('User name is:', userName); console.log(10 + 5); // Output: 15
2. alert() (For Immediate User Notification)
Creates a modal pop-up box that stops script execution until the user clicks 'OK'.
javascript alert('Welcome to our site!');
3. prompt() (For Simple User Input)
Creates a modal pop-up box asking the user for input. The return value is the text the user entered (always a string).
javascript let userResponse = prompt('Please enter your age:'); console.log('User entered:', userResponse);
// If the user cancels, prompt returns null.