01-02 Fundamental Concepts
01-02 Fundamental Concepts
Object Name
Property
Method
Dot Syntax
Main Event
Modifying a Property
ObjectName.PropertyName = NewValue;
ObjectName[PropertyName] = NewValue;
Person.FirstName = “Ram”;
Person[“FirstName”]=”Ram”;
3. Method:
A method is a function that is associated with an object.
Methods can access and modify the object's properties by using the this keyword,
which refers to the object the method belongs to.
A method is a set of statements performed by an object when it receives a
message.
Example of a Method:
Syntax : ObjectName.methodName();
Person.FullName();
Here, FullName is a method of the Person object, and it returns the concatenated
string of FirstName and LastName.
Example 2:
Subject: Java Script Notes Print Date: [16/Oct/24], Page 2 of 8
o Submit a button on the form is an object.
o The dimensions of the buttons are the properties of the object.
o When you click on the submit button, it causes the button to process the
method.
In this example:
person.name accesses the name property of the person object.
person.greet() calls the greet method of the person object.
Using addEventListener()
This method allows you to add multiple event listeners to an element and is the preferred
method for handling events: