js object hierarchy

JavaScript Object Hierarchy Course


---

## Introduction
JavaScript follows an object-oriented approach where objects have properties and methods. Understanding the JavaScript object hierarchy helps in efficient coding and debugging.

## Hierarchy of JavaScript Objects
Below is the general hierarchy of JavaScript objects:

Window ├── Document │ ├── Forms │ ├── Images │ ├── Links ├── History ├── Navigator


---

## Window Object
The `window` object is the topmost object in the JavaScript hierarchy. It represents the browser window.

### Window Properties
- `defaultStatus`
- `frames`
- `opener`
- `parent`
- `scroll`
- `self`
- `status`
- `top`

### Window Methods
- `alert()`
- `blur()`
- `close()`
- `confirm()`
- `focus()`
- `open()`
- `prompt()`
- `setTimeout()`
- `clearTimeout()`

### Window Event Handlers
- `onLoad`
- `onUnload`
- `onBlur`
- `onFocus`

---

## History Object
The `history` object keeps track of visited pages.

### History Methods
- `length`
- `forward()`
- `go()`
- `back()`

---

## Navigator Object
The `navigator` object provides information about the browser.

### Navigator Properties
- `appCodeName`
- `appName`
- `appVersion`
- `mimeTypes`
- `plugins`
- `userAgent`
- `javaEnabled()`

---

## Document Object
The `document` object represents the HTML page.

### Document Properties
- `alinkColor`
- `anchors`
- `applets`
- `bgColor`
- `cookie`
- `fgColor`
- `forms`
- `images`
- `lastModified`
- `linkColor`
- `links`
- `location`
- `referrer`
- `title`
- `vlinkColor`

### Document Methods
- `clear()`
- `close()`
- `open()`
- `write()`
- `writeln()`

---

## Image Object
An image object allows manipulation of images on a webpage.

### Image Properties
- `border`
- `complete`
- `height`
- `hspace`
- `lowsrc`
- `name`
- `src`
- `vspace`
- `width`

---

## Form Object
The `form` object represents an HTML form.

### Form Properties
- `action`
- `elements`
- `encoding`
- `method`
- `name`
- `target`

### Form Methods
- `submit()`
- `reset()`

### Form Event Handlers
- `onSubmit`
- `onReset`

---

## Text Input Object
A text input object represents an input field.

### Text Input Properties
- `defaultValue`
- `name`
- `type`
- `value`

### Text Input Methods
- `focus()`
- `blur()`
- `select()`

### Text Input Event Handlers
- `onBlur`
- `onChange`
- `onFocus`
- `onSelect`

---

## Built-in Objects

### Array Object
The `Array` object is used to store multiple values.

#### Creating an Array
```javascript
var myCars = new Array("Saab", "Volvo", "BMW");

Accessing Array Elements

document.write(myCars[0]); // Output: Saab

Modifying an Array

myCars[0] = "Opel";

Date Object

The Date object is used to handle dates and times.
Creating a Date Object

var myDate = new Date();

Setting a Specific Date

myDate.setFullYear(2010, 0, 14);

Comparing Dates

var today = new Date();
if (myDate > today) {
  alert("Future Date");
} else {
  alert("Past Date");
}

Math Object

The Math object allows mathematical calculations.
Constants

Math.PI
Math.SQRT2

Methods

Math.round(4.7);  // Output: 5
Math.random();    // Output: Random number between 0 and 1
Math.floor(Math.random() * 10); // Output: Random number between 0 and 10

String Object

The String object is used to manipulate text.
Finding String Length

var txt = "Hello World!";
document.write(txt.length); // Output: 12

Converting to Uppercase

document.write(txt.toUpperCase()); // Output: HELLO WORLD!

Conclusion

This course covered the JavaScript object hierarchy, including key objects like window, document, navigator, and built-in objects like Array, Date, Math, and String. Understanding these objects is crucial for effective JavaScript programming.

Quiz

To mark this module as complete, you must finish this quiz. Once submitted, you'll need to wait 2 hours before attempting it again.