JS Window Object 🎯

beginner
21 min

JS Window Object 🎯

Welcome to our deep dive into the JS Window Object! This tutorial is perfect for both beginners and intermediate learners. Let's explore this essential part of JavaScript together. 💡

Understanding the Window Object 📝

The window object in JavaScript represents the entire browser window or web page. It's the global object in JavaScript and provides a variety of properties and methods to interact with the browser and document.

Properties of the Window Object 📝

Here are some crucial properties of the window object:

  1. window.location: This property represents the current URL of the document.
  2. window.history: It provides access to the history of visited URLs.
  3. window.screen: This property contains information about the user's screen size.

Methods of the Window Object 📝

  1. window.alert(): This method displays a small dialog box with a specified message.
  2. window.confirm(): This method displays a dialog box with a specified message and two buttons - OK and Cancel.
  3. window.prompt(): This method displays a dialog box with a specified message and lets the user enter a single line of text.

Practical Examples 💡

Example 1: Displaying a Message with alert()

javascript
// Simple usage of alert() window.alert("Hello, World!");

Example 2: Confirming User Input with confirm()

javascript
// Using confirm() to ask for user input let result = window.confirm("Are you sure?"); console.log(result);

Quiz Time 📝

Quick Quiz
Question 1 of 1

Which method displays a dialog box with a specified message and two buttons - OK and Cancel?

Wrapping Up 💡

That's it for our deep dive into the JS Window Object! We hope you found this tutorial helpful. Stay tuned for more exciting JavaScript lessons here at CodeYourCraft. ✅

Happy coding! 🎯