JavaScript Events
A mode change of an object is known as an event. In html, there are various events that indicate that some activity has been performed by the user or by the browser. When JavaScript code is included in HTML, js reacts to these events and allows execution. This process of reacting to events is called event handling.
The following types of events can occur in JavaScript, which are explained in detail
onclick events:
This is the most commonly used event type that occurs when the user clicks the left button of his mouse. You can put your validation, warning etc against this event type.
Example
Edit it yourselfconst cityName = {
city1 : "mumbai",
city2 : "dilhi",
city3 : "ahmedabad"
};
The cityName
is shown as the object as shown in the example.
city1, city1, city1 is the key
to this object.
Mumbai, delhi, ahmedabad is the value of key this object.
Each member of the object has a key:value
pair is separated by a comma and enclosed in spiral brackets { }
.
JavaScript Object Properties
Object properties are defined as a simple connection between a name and a value
All properties have a name and value is one of the attributes attached to the property, defining the access granted to the property.
- The following example shows the structure of the object property.
Example
Edit it yourself<script>
const city = {
name: 'mumbai'
}
city.name = 'mumbai'
city['name'] = 'red'
document.write(car.color);
</script>
In the example above, City is the object and name is the object property.
Mumbai, delhi, ahmedabad is the value of key this object.
Mumbai, delhi, ahmedabad is the value of key this object.
JavaScript Object Methods
JavaScript methods are functions that allow an object to do something or do something for it.
Methods are useful for performing complex mathematical operations on a group of local properties and parameters after the object's content is displayed on the screen.
Different types of methods can be used in JavaScript object method which can refer to any object using methods like call (), apply (), and bind ().
Example
Edit it yourselfconst country = {
state: "28",
pm: "narendra modi",
code: 5566,
bio: function() {
return this.pm;
}
};
document.write(country.bio());
Understand in the example, first create an object named country.
And then in the example state, pm, and code which can be called the property of the object.
And is then called by the function.
- In this lecture you have learned about JavaScript function, hopefully you have understood the function from this lecture.