Methods in JavaScript can be said as an action, which is performed on objects. It is a property like an employee name, department, eid, etc with properties “Amit”, “Marketing”, “001”, etc.
To access object methods in JavaScript −
object.method()
Let’s see an example,
employee.details()
Example
You can try to run the following code to access object methods −
<html>
<head>
<script>
var employee = {
empname: "Amit",
department : "Marketing",
id : 001,
details : function() {
return this.empname + " with ID: " + this.id;
}
};
document.write(employee.details());
</script>
</head>
</html>Output
