{"id":5768,"date":"2021-03-26T05:49:54","date_gmt":"2021-03-26T05:49:54","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=5768"},"modified":"2021-03-26T05:49:54","modified_gmt":"2021-03-26T05:49:54","slug":"methods-in-javascript","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/","title":{"rendered":"Methods in JavaScript"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In JavaScript, however, a\u00a0<em>method<\/em>\u00a0is a\u00a0<strong>function<\/strong>\u00a0that belongs to an\u00a0<strong><em>object<\/em><\/strong>. A JavaScript\u00a0<strong>method<\/strong>\u00a0is a property containing a\u00a0<strong>function definition<\/strong>.<\/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<strong><em>method<\/em>\u00a0<\/strong>is a\u00a0<em>function\u00a0<\/em>that belongs to an\u00a0<strong><em>object<\/em><\/strong>.<\/li><li>JavaScript\u00a0<strong>methods\u00a0<\/strong>are the actions that can be performed on <strong><em>objects<\/em><\/strong>.<\/li><li>A JavaScript\u00a0<strong>method<\/strong>\u00a0is a property containing a\u00a0<em>function definition<\/em>.<\/li><li>Accessing the object method is done with the following syntax:\u00a0<em>objectName.methodName()<\/em><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Just similar to the <strong>functions<\/strong> in JavaScript methods are also classified in two categories:- <\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Predefined <\/li><li>User-defined<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Predefined methods can be used directly by calling and giving parameter values (if required). while user-defined methods are first declared, defined, and then used in the program. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Deceleration and definitions of User-defined methods are done together we could understand better seeing the below code.<strong><br>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<h2 class=\"has-medium-font-size wp-block-heading\">How to access the Object Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">we can access the object method with the following syntax stated below:- <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>objectName.methodName()<\/em><\/p>\n\n\n\n<h2 class=\"has-medium-font-size wp-block-heading\">How to add the method to Object.<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nperson.name = function () {\n    return this.firstName + &quot; &quot; + this.lastName;\n};\n<\/pre><\/div>\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>We could also directly use the built-in method.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar message = &quot;Display message of your choice&quot;;\nvar x = message.toUpperCase();\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The above method would just convert the text entered as a message to uppercase. <\/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>Want to know the difference between <strong>Function <\/strong>and <strong>Method <\/strong>in JavaScript? Just click\u00a0<a href=\"https:\/\/www.scmgalaxy.com\/tutorials\/difference-between-function-and-method-in-javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">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><li>Let\u2019s see an example for <strong>User form validation<\/strong> 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<strong> understand JavaScript<\/strong>. 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><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In JavaScript, however, a\u00a0method\u00a0is a\u00a0function\u00a0that belongs to an\u00a0object. A JavaScript\u00a0method\u00a0is a property containing a\u00a0function definition. Few Important things of Methods:- [&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":[5172,5176,5181,5178,5177,5179,5180],"class_list":["post-5768","post","type-post","status-publish","format-standard","hentry","category-javascript","category-websites","tag-javascript-methods","tag-methods-in-javascript","tag-predefined-methods-in-javascript","tag-user-defined-and-predefined-method","tag-userdefined-and-predefined-methods-in-javascript","tag-userdefined-method","tag-userdefined-method-in-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Methods 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\/methods-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Methods in JavaScript - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"In JavaScript, however, a\u00a0method\u00a0is a\u00a0function\u00a0that belongs to an\u00a0object. A JavaScript\u00a0method\u00a0is a property containing a\u00a0function definition. Few Important things of Methods:- [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-26T05:49:54+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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/\"},\"author\":{\"name\":\"abhishek k\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/143500a93b88a96d3c9602b3df804cb6\"},\"headline\":\"Methods in JavaScript\",\"datePublished\":\"2021-03-26T05:49:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/\"},\"wordCount\":266,\"commentCount\":0,\"keywords\":[\"javascript methods\",\"Methods in JavaScript\",\"predefined methods in javascript\",\"user defined and predefined method\",\"userdefined and predefined methods in javascript\",\"userdefined method\",\"userdefined method in javascript\"],\"articleSection\":[\"JavaScript\",\"Websites\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/\",\"name\":\"Methods in JavaScript - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-03-26T05:49:54+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/143500a93b88a96d3c9602b3df804cb6\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/methods-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Methods 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":"Methods 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\/methods-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Methods in JavaScript - scmGalaxy","og_description":"In JavaScript, however, a\u00a0method\u00a0is a\u00a0function\u00a0that belongs to an\u00a0object. A JavaScript\u00a0method\u00a0is a property containing a\u00a0function definition. Few Important things of Methods:- [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/","og_site_name":"scmGalaxy","article_published_time":"2021-03-26T05:49:54+00:00","author":"abhishek k","twitter_card":"summary_large_image","twitter_misc":{"Written by":"abhishek k","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/"},"author":{"name":"abhishek k","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/143500a93b88a96d3c9602b3df804cb6"},"headline":"Methods in JavaScript","datePublished":"2021-03-26T05:49:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/"},"wordCount":266,"commentCount":0,"keywords":["javascript methods","Methods in JavaScript","predefined methods in javascript","user defined and predefined method","userdefined and predefined methods in javascript","userdefined method","userdefined method in javascript"],"articleSection":["JavaScript","Websites"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/","name":"Methods in JavaScript - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-03-26T05:49:54+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/143500a93b88a96d3c9602b3df804cb6"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/methods-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Methods 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\/5768","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=5768"}],"version-history":[{"count":2,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5768\/revisions"}],"predecessor-version":[{"id":5773,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5768\/revisions\/5773"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=5768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=5768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=5768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}