xxxxxxxxxx
Mothod:
In object-oriented programming, a method is associated with a class, mothod alwasy comes with an object.
Function:
Function can used to process or operate the parameter, function may or may not be return any value.
xxxxxxxxxx
Function — a set of instructions that perform a task. We can define a
function using the function keyword, followed by Name and optional parameters.
Body of function is enclosed in Curly braces.
Method — a set of instructions that are associated with an object.
A JavaScript method is a property of an object that contains a function
definition. Methods are functions stored as object properties.
Object method can be accessed with the following syntax:
object = {
methodName: function() {
// Content
}
};
object.methodName()
xxxxxxxxxx
Functions and methods are almost the same thing. They can both be called to execute the code in
them. The difference between a function and a method is that a method will always be attached to
an object. Usually methods change something about that particular object (you can think of the
attached object as a sort of permanent argument passed to the method).