difference between functions and methods code example

Example: Difference between Methods and Functions in JavaScript

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()