{"id":5767,"date":"2021-03-26T03:36:17","date_gmt":"2021-03-26T03:36:17","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=5767"},"modified":"2021-03-26T13:14:45","modified_gmt":"2021-03-26T13:14:45","slug":"difference-between-function-and-method-in-javascript","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/","title":{"rendered":"Difference between Function and Method in JavaScript"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>So what\u2019s the different between the two?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Methods have a \u201creceiver\u201d while functions do not.<\/strong><\/li><li><strong>Functions <\/strong>and <strong>methods <\/strong>are the same in JavaScript, but a <strong>method <\/strong>is a <strong>function<\/strong>, which is a property of an object.<\/li><li>Syntax for <strong>calling\/ definition\/declaration<\/strong> of <strong>functions <\/strong>and <strong>methods <\/strong>are different.<\/li><li>A function can be called directly by its name but methods are called by its object name and its method name using dot notation or square bracket notation.<\/li><li><strong>Function <\/strong>passes the data and <strong>methods <\/strong>operates the data passed in the <em>class<\/em>.<\/li><li>A function lives on its own but method is a function associated with an object property.<\/li><li>Data passed to a function is explicit but method implicitly passes the object on which it was called.<\/li><\/ul>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>Lets see detailed difference between them:-<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A function in JavaScript is similar to a procedure \u2014>a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Few Important things of functions:-<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The function is executed when something calls\/invokes it.<\/li><li>The name may contain letters, digits, dollar signs, underscore.<\/li><li>Parameters are listed inside round parenthesis after the name of the function.<\/li><li>Arguments are values a function receives when it is invoked.<\/li><li>When the control reaches the return statement, js will stop executing and the value is returned to the caller.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>There are three steps of Functions as well as Methods to use in the program.<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Declaration<\/strong><\/li><li><strong>Definition.<\/strong><\/li><li><strong>Call<\/strong><\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">In JavaScript function\u00a0<em>declaration\u00a0<\/em>and\u00a0<em>definition\u00a0<\/em>are mostly done together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A JavaScript <strong>method <\/strong>is a property of an object that contains a function definition. Methods are functions stored as object properties.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Few Important things of Methods:-<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>In JavaScript, however, a\u00a0<em>method<\/em>\u00a0is a\u00a0<strong>function<\/strong>\u00a0that belongs to an\u00a0<strong><em>object<\/em><\/strong>.<\/li><li>JavaScript <strong>methods <\/strong>are the actions that can be performed on objects. <\/li><li>A JavaScript\u00a0<strong>method<\/strong>\u00a0is a property containing a\u00a0<strong>function definition<\/strong>. <\/li><li>Accessing the object method is done with the following syntax: <em>objectName.methodName()<\/em><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax of Function<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar func = function(a, b) {\n    var sum = a + b;\n    return sum;\n}\n  \nconsole.log(sum(1, 2));\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax of Methods<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nobject = {\n    methodName: function() {\n        \/\/ Content\n    }\n};\n\nobject.methodName()\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Few important links for learning:-<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Let\u2019s see an example for User form validation in JavaScript. click\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/registration-form-validation-using-javascript\/\" target=\"_blank\">here<\/a>.<\/li><li>Let\u2019s understand JavaScript. what and how? click\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/a-brief-description-of-javascript\/\" target=\"_blank\">here<\/a>.<\/li><li>Want to know what is\u00a0<strong>function<\/strong>\u00a0and how to use them in JavaScript? Just click\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/function-in-javascript\/\" target=\"_blank\">here<\/a>.<\/li><li>Want to know what are\u00a0<strong>variables\u00a0<\/strong>and how to use them in JavaScript? Just click\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/variables-in-javascript-var-let-const\/\" target=\"_blank\">here<\/a>.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So what\u2019s the different between the two? Methods have a \u201creceiver\u201d while functions do not. Functions and methods are the [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[16,156],"tags":[5168,5169,5143,5172,5175],"class_list":["post-5767","post","type-post","status-publish","format-standard","hentry","category-javascript","category-websites","tag-difference-between-function-and-method-in-javascript","tag-function-and-method-in-javascript","tag-javascript-function","tag-javascript-methods","tag-what-is-the-difference-between-function-and-javascritp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Difference between Function and Method in JavaScript - scmGalaxy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Difference between Function and Method in JavaScript - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"So what\u2019s the different between the two? Methods have a \u201creceiver\u201d while functions do not. Functions and methods are the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-26T03:36:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-26T13:14:45+00:00\" \/>\n<meta name=\"author\" content=\"abhishek k\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"abhishek k\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/\"},\"author\":{\"name\":\"abhishek k\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/143500a93b88a96d3c9602b3df804cb6\"},\"headline\":\"Difference between Function and Method in JavaScript\",\"datePublished\":\"2021-03-26T03:36:17+00:00\",\"dateModified\":\"2021-03-26T13:14:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/\"},\"wordCount\":408,\"commentCount\":2,\"keywords\":[\"Difference between Function and Method in JavaScript\",\"Function and Method in JavaScript\",\"javascript function\",\"javascript methods\",\"what is the difference between function and javascritp\"],\"articleSection\":[\"JavaScript\",\"Websites\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/\",\"name\":\"Difference between Function and Method in JavaScript - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-03-26T03:36:17+00:00\",\"dateModified\":\"2021-03-26T13:14:45+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/143500a93b88a96d3c9602b3df804cb6\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/difference-between-function-and-method-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Difference between Function and Method in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/143500a93b88a96d3c9602b3df804cb6\",\"name\":\"abhishek k\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7e05a074cc5eeb0b13b5768bbfd8f7793851f739965234dc5aaae590b9c8677f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7e05a074cc5eeb0b13b5768bbfd8f7793851f739965234dc5aaae590b9c8677f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7e05a074cc5eeb0b13b5768bbfd8f7793851f739965234dc5aaae590b9c8677f?s=96&d=mm&r=g\",\"caption\":\"abhishek k\"},\"description\":\"Abhishek is a full-stack developer that provides the solution for the design and analysis of Website and Mobile Application. Expertise in HTML, CSS, JAVASCRIPT, LARAVEL.\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/abhishek\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Difference between Function and Method in JavaScript - scmGalaxy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Difference between Function and Method in JavaScript - scmGalaxy","og_description":"So what\u2019s the different between the two? Methods have a \u201creceiver\u201d while functions do not. Functions and methods are the [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/","og_site_name":"scmGalaxy","article_published_time":"2021-03-26T03:36:17+00:00","article_modified_time":"2021-03-26T13:14:45+00:00","author":"abhishek k","twitter_card":"summary_large_image","twitter_misc":{"Written by":"abhishek k","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/"},"author":{"name":"abhishek k","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/143500a93b88a96d3c9602b3df804cb6"},"headline":"Difference between Function and Method in JavaScript","datePublished":"2021-03-26T03:36:17+00:00","dateModified":"2021-03-26T13:14:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/"},"wordCount":408,"commentCount":2,"keywords":["Difference between Function and Method in JavaScript","Function and Method in JavaScript","javascript function","javascript methods","what is the difference between function and javascritp"],"articleSection":["JavaScript","Websites"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/","name":"Difference between Function and Method in JavaScript - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-03-26T03:36:17+00:00","dateModified":"2021-03-26T13:14:45+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/143500a93b88a96d3c9602b3df804cb6"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Difference between Function and Method in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/143500a93b88a96d3c9602b3df804cb6","name":"abhishek k","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/7e05a074cc5eeb0b13b5768bbfd8f7793851f739965234dc5aaae590b9c8677f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/7e05a074cc5eeb0b13b5768bbfd8f7793851f739965234dc5aaae590b9c8677f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7e05a074cc5eeb0b13b5768bbfd8f7793851f739965234dc5aaae590b9c8677f?s=96&d=mm&r=g","caption":"abhishek k"},"description":"Abhishek is a full-stack developer that provides the solution for the design and analysis of Website and Mobile Application. Expertise in HTML, CSS, JAVASCRIPT, LARAVEL.","url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/abhishek\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=5767"}],"version-history":[{"count":2,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5767\/revisions"}],"predecessor-version":[{"id":5776,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5767\/revisions\/5776"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=5767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=5767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=5767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}