<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Function and Method in JavaScript Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/function-and-method-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/function-and-method-in-javascript/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Fri, 26 Mar 2021 13:14:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>Difference between Function and Method in JavaScript</title>
		<link>https://www.scmgalaxy.com/tutorials/difference-between-function-and-method-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/difference-between-function-and-method-in-javascript/#comments</comments>
		
		<dc:creator><![CDATA[abhishek k]]></dc:creator>
		<pubDate>Fri, 26 Mar 2021 03:36:17 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[Difference between Function and Method in JavaScript]]></category>
		<category><![CDATA[Function and Method in JavaScript]]></category>
		<category><![CDATA[javascript function]]></category>
		<category><![CDATA[javascript methods]]></category>
		<category><![CDATA[what is the difference between function and javascritp]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/?p=5767</guid>

					<description><![CDATA[<p>So what’s the different between the two? Methods have a “receiver” while functions do not. Functions and methods are the [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/difference-between-function-and-method-in-javascript/">Difference between Function and Method in JavaScript</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="has-medium-font-size wp-block-paragraph"><strong>So what’s the different between the two?</strong></p>



<ul class="wp-block-list"><li><strong>Methods have a “receiver” 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>



<p class="has-medium-font-size wp-block-paragraph"><strong>Lets see detailed difference between them:-</strong></p>



<p class="wp-block-paragraph">A function in JavaScript is similar to a procedure —>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>



<p class="wp-block-paragraph"><strong>Few Important things of functions:-</strong></p>



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



<p class="wp-block-paragraph"><strong>There are three steps of Functions as well as Methods to use in the program.</strong></p>



<ol class="wp-block-list"><li><strong>Declaration</strong></li><li><strong>Definition.</strong></li><li><strong>Call</strong></li></ol>



<p class="wp-block-paragraph">In JavaScript function <em>declaration </em>and <em>definition </em>are mostly done together.</p>



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



<p class="wp-block-paragraph"><strong>Few Important things of Methods:-</strong></p>



<ul class="wp-block-list"><li>In JavaScript, however, a <em>method</em> is a <strong>function</strong> that belongs to an <strong><em>object</em></strong>.</li><li>JavaScript <strong>methods </strong>are the actions that can be performed on objects. </li><li>A JavaScript <strong>method</strong> is a property containing a <strong>function definition</strong>. </li><li>Accessing the object method is done with the following syntax: <em>objectName.methodName()</em></li></ul>



<p class="wp-block-paragraph"><strong>Syntax of Function</strong></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
var func = function(a, b) {
    var sum = a + b;
    return sum;
}
  
console.log(sum(1, 2));
</pre></div>


<p class="wp-block-paragraph"><strong>Syntax of Methods</strong></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
object = {
    methodName: function() {
        // Content
    }
};

object.methodName()
</pre></div>


<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Few important links for learning:-</strong></p>



<ol class="wp-block-list"><li>Let’s see an example for User form validation in JavaScript. click <a rel="noreferrer noopener" href="https://www.scmgalaxy.com/tutorials/registration-form-validation-using-javascript/" target="_blank">here</a>.</li><li>Let’s understand JavaScript. what and how? click <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 <strong>function</strong> and how to use them in JavaScript? Just click <a rel="noreferrer noopener" href="https://www.scmgalaxy.com/tutorials/function-in-javascript/" target="_blank">here</a>.</li><li>Want to know what are <strong>variables </strong>and how to use them in JavaScript? Just click <a rel="noreferrer noopener" href="https://www.scmgalaxy.com/tutorials/variables-in-javascript-var-let-const/" target="_blank">here</a>.</li></ol>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/difference-between-function-and-method-in-javascript/">Difference between Function and Method in JavaScript</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/difference-between-function-and-method-in-javascript/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
