🌐 Basic BOM (Browser Object Model)
Last Updated: 09 Oct 2025
BOM (Browser Object Model) allows JavaScript to interact with the browser window and control browser features (like alerts, location, history, and navigator).
Hinglish Tip 🗣: BOM ka matlab hai “browser ka model” — jaise browser ka control hum JS ke through le sakte hain.
BOM Popup?
- A popup is a window that appears on top of the current window.
- JavaScript provides simple popup dialogs to interact with users directly in the browser.
- These include:
alert()→ show messageconfirm()→ ask yes/no questionprompt()→ take input from user
🔔 1. alert()
- Displays a message box with OK button.
- No return value.
alert("Hello User!");
alert("Welcome to JavaScript BOM Tutorial!");
Hinglish Tip 🗣: Ye sirf message dikhata hai — user koi value return nahi karta.
✅ 2. confirm()
- Displays a dialog box with OK and Cancel buttons.
- Returns true if OK clicked, false if Cancel clicked.
let isSure = confirm("Are you sure you want to continue?");
console.log(isSure); // true or false depending on user click
Hinglish Tip 🗣: Confirm se user ka yes/no ya true/false milta hai.
📝 3. prompt()
- Displays a popup input box for the user to enter text.
- Returns the entered string, or null if Cancel clicked.
let name = prompt("Enter your name:");
console.log(name);
Hinglish Tip 🗣: Browser me ek chhota input box show karta hai.
💡 Quick Practice
- Show an alert with "Welcome to JS BOM".
- Ask user "Do you like JavaScript?" using confirm() and print the result.
- Take user name using prompt() and greet them using console.log.