<?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>Parameters Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/parameters/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/parameters/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 21 Feb 2026 07:13:46 +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>Understanding Parameters: Use Cases, Architecture, Workflow, and Getting Started Guide</title>
		<link>https://www.scmgalaxy.com/tutorials/understanding-parameters-use-cases-architecture-workflow-and-getting-started-guide/</link>
					<comments>https://www.scmgalaxy.com/tutorials/understanding-parameters-use-cases-architecture-workflow-and-getting-started-guide/#respond</comments>
		
		<dc:creator><![CDATA[Vijay K]]></dc:creator>
		<pubDate>Mon, 16 Jun 2025 12:37:00 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CodingConcepts]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Parameters]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ProgrammingBestPractices]]></category>
		<category><![CDATA[SoftwareArchitecture]]></category>
		<category><![CDATA[SoftwareDevelopment]]></category>
		<category><![CDATA[TechTutorial]]></category>
		<category><![CDATA[Variables]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=12793</guid>

					<description><![CDATA[<p>What are Parameters? Parameters are variables used in programming that allow you to pass data or values into functions, methods, [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/understanding-parameters-use-cases-architecture-workflow-and-getting-started-guide/">Understanding Parameters: Use Cases, Architecture, Workflow, and Getting Started Guide</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="683" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-114-1024x683.png" alt="" class="wp-image-12804" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-114-1024x683.png 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-114-300x200.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-114-768x512.png 768w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-114.png 1536w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">What are Parameters?</h3>



<p class="wp-block-paragraph"><strong>Parameters</strong> are variables used in programming that allow you to pass <strong>data</strong> or <strong>values</strong> into functions, methods, or procedures to enable them to perform tasks with varying inputs. When you define a function or method, you can specify parameters in its declaration, which are placeholders for the values that will be passed when the function is called. Parameters act as input data for the function and allow it to process different values each time it is executed.</p>



<p class="wp-block-paragraph">Parameters are essential in making <strong>functions</strong> reusable and dynamic. By defining parameters, functions can perform tasks based on the values passed to them, without having to hard-code specific data. They serve as a critical component of function-based programming and are used in many programming languages such as <strong>Python</strong>, <strong>Java</strong>, <strong>JavaScript</strong>, <strong>C</strong>, <strong>C++</strong>, and more.</p>



<p class="wp-block-paragraph">In many cases, <strong>parameters</strong> are also referred to as <strong>arguments</strong>, though there is a subtle distinction between the two:</p>



<ul class="wp-block-list">
<li><strong>Parameter</strong>: The variable in the function definition.</li>



<li><strong>Argument</strong>: The actual value passed to the parameter when the function is called.</li>
</ul>



<p class="wp-block-paragraph">For example, consider a simple function that adds two numbers:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def add_numbers(a, b):
    return a + b

</pre></div>


<p class="wp-block-paragraph">Here, <code>a</code> and <code>b</code> are parameters. When you call the function with actual values, those values are arguments:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
add_numbers(3, 5)

</pre></div>


<p class="wp-block-paragraph">In this case, <code>3</code> and <code>5</code> are arguments passed to the <code>a</code> and <code>b</code> parameters of the <code>add_numbers</code> function.</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">What are the Major Use Cases of Parameters?</h3>



<p class="wp-block-paragraph">Parameters are used in a wide range of programming scenarios. Below are the major use cases:</p>



<h4 class="wp-block-heading">1. <strong>Dynamic Function Behavior</strong></h4>



<p class="wp-block-paragraph">Parameters allow functions to behave dynamically by taking input values that determine the function&#8217;s behavior. Instead of hardcoding values, parameters allow the same function to be executed with different inputs, making the function reusable for different scenarios.</p>



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



<ul class="wp-block-list">
<li>A <strong>sum function</strong> can be reused for adding any two numbers, and the numbers are passed as parameters to define the function&#8217;s behavior.</li>
</ul>



<h4 class="wp-block-heading">2. <strong>Encapsulation of Complex Operations</strong></h4>



<p class="wp-block-paragraph">Functions that perform <strong>complex operations</strong> (e.g., calculations, data processing) often require different values for each operation. Parameters encapsulate the input data, allowing the function to work on a variety of inputs without modifying the core logic.</p>



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



<ul class="wp-block-list">
<li>A <strong>file processing function</strong> can take parameters for the file path, encoding, and output format, enabling the same function to process different files.</li>
</ul>



<h4 class="wp-block-heading">3. <strong>Code Reusability</strong></h4>



<p class="wp-block-paragraph">Parameters increase <strong>code reusability</strong> by allowing functions to work with different inputs and perform similar operations without writing multiple versions of the same function.</p>



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



<ul class="wp-block-list">
<li>A <strong>data sorting function</strong> can be reused with different datasets and sort orders by passing the dataset and order type as parameters.</li>
</ul>



<h4 class="wp-block-heading">4. <strong>Configuration of Functions</strong></h4>



<p class="wp-block-paragraph">Parameters allow functions to be configured and customized without changing their internal logic. This allows greater flexibility, as parameters control aspects of the function&#8217;s execution, like <strong>timeouts</strong>, <strong>limits</strong>, and <strong>environment settings</strong>.</p>



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



<ul class="wp-block-list">
<li>A <strong>server connection function</strong> might take parameters for the server address, port, and authentication details, allowing the function to connect to various servers with different configurations.</li>
</ul>



<h4 class="wp-block-heading">5. <strong>Control Flow and Decision Making</strong></h4>



<p class="wp-block-paragraph">Parameters can control the <strong>flow of a program</strong>, allowing developers to implement decision-making logic within functions based on the input values. This can help in implementing <strong>conditional operations</strong> and <strong>branching logic</strong>.</p>



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



<ul class="wp-block-list">
<li>A <strong>payment processing function</strong> could take a <code>payment_method</code> parameter to determine whether the payment is processed via credit card, PayPal, or another method.</li>
</ul>



<h4 class="wp-block-heading">6. <strong>Interfacing with External Systems</strong></h4>



<p class="wp-block-paragraph">In distributed systems or when working with external APIs, parameters serve as the mechanism to pass data between different services, applications, or system layers. They act as <strong>data carriers</strong> that transport necessary information across systems.</p>



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



<ul class="wp-block-list">
<li>An <strong>API request</strong> might take parameters like <code>user_id</code>, <code>action_type</code>, and <code>time_range</code> to request specific data from a server.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">How Parameters Work Along with Architecture?</h3>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="683" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-115-1024x683.png" alt="" class="wp-image-12805" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-115-1024x683.png 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-115-300x200.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-115-768x512.png 768w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-115.png 1536w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">In programming, parameters fit into the overall architecture of functions, methods, and procedures. Below is an explanation of how parameters are used within the architecture of a function and the general software architecture.</p>



<h4 class="wp-block-heading">1. <strong>Function Declaration</strong></h4>



<p class="wp-block-paragraph">When you define a function or method, you specify the parameters within the function’s <strong>declaration</strong>. These parameters act as placeholders for the values that will be passed when the function is invoked.</p>



<p class="wp-block-paragraph">Example in Python:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def greet_user(username):
    print(f&quot;Hello, {username}!&quot;)

</pre></div>


<p class="wp-block-paragraph">Here, <code>username</code> is a parameter that is used in the function <code>greet_user</code>. When you call the function, you pass an <strong>argument</strong> to this parameter:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
greet_user(&quot;Alice&quot;)

</pre></div>


<h4 class="wp-block-heading">2. <strong>Function Call</strong></h4>



<p class="wp-block-paragraph">When a function is invoked, you pass values, known as <strong>arguments</strong>, to the parameters in the function definition. These arguments replace the parameters with specific data when the function executes. The argument values are assigned to the corresponding parameters, and the function uses them to perform its operations.</p>



<h4 class="wp-block-heading">3. <strong>Parameter Scope</strong></h4>



<p class="wp-block-paragraph">The scope of a parameter is <strong>local</strong> to the function or method in which it is defined. This means the parameter can only be used inside the function or method where it is declared. Once the function execution is complete, the parameter value is discarded.</p>



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


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def calculate_area(radius):
    area = 3.14 * radius * radius  # radius is a parameter
    return area

# radius is not accessible outside the function

</pre></div>


<h4 class="wp-block-heading">4. <strong>Default Parameters</strong></h4>



<p class="wp-block-paragraph">Some programming languages allow <strong>default parameter values</strong>, which are used when no argument is passed to the function. This makes parameters optional.</p>



<p class="wp-block-paragraph">Example in Python:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def greet_user(username=&quot;Guest&quot;):
    print(f&quot;Hello, {username}!&quot;)

greet_user()  # Uses the default value &quot;Guest&quot;
greet_user(&quot;Alice&quot;)  # Uses the provided argument &quot;Alice&quot;

</pre></div>


<h4 class="wp-block-heading">5. <strong>Varied Number of Parameters (Arbitrary Arguments)</strong></h4>



<p class="wp-block-paragraph">Some languages support functions that accept a <strong>variable number of parameters</strong>, often using a special syntax. In Python, this is achieved using <code>*args</code> for non-keyword arguments or <code>**kwargs</code> for keyword arguments.</p>



<p class="wp-block-paragraph">Example in Python:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def sum_numbers(*args):
    return sum(args)

print(sum_numbers(1, 2, 3))  # Output: 6

</pre></div>


<p class="wp-block-paragraph">Here, <code>*args</code> allows the function to accept an arbitrary number of arguments.</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">Basic Workflow of Parameters</h3>



<p class="wp-block-paragraph">The basic workflow for using parameters in functions follows a few simple steps:</p>



<ol class="wp-block-list">
<li><strong>Define Parameters in Function Declaration</strong>
<ul class="wp-block-list">
<li>Define the function and specify the parameters inside the parentheses.</li>
</ul>
</li>



<li><strong>Call the Function and Pass Arguments</strong>
<ul class="wp-block-list">
<li>When calling the function, pass values (arguments) that correspond to the parameters defined in the function.</li>
</ul>
</li>



<li><strong>Use Parameters Inside the Function</strong>
<ul class="wp-block-list">
<li>Inside the function, use the parameter values to perform computations or execute specific tasks based on the input.</li>
</ul>
</li>



<li><strong>Return Results (If Applicable)</strong>
<ul class="wp-block-list">
<li>The function can return a value based on the parameters, which can be used elsewhere in the program.</li>
</ul>
</li>



<li><strong>Handle Optional or Variable Parameters</strong>
<ul class="wp-block-list">
<li>Define default values for parameters or use variable argument techniques (like <code>*args</code> or <code>**kwargs</code>) to make the function more flexible.</li>
</ul>
</li>
</ol>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h3 class="wp-block-heading">Step-by-Step Getting Started Guide for Parameters</h3>



<p class="wp-block-paragraph">Here’s a step-by-step guide to help you understand and implement parameters in your programs:</p>



<h4 class="wp-block-heading">Step 1: <strong>Define a Simple Function</strong></h4>



<p class="wp-block-paragraph">Start by creating a simple function that accepts a single parameter:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def say_hello(name):
    print(f&quot;Hello, {name}!&quot;)

</pre></div>


<p class="wp-block-paragraph">This function takes <code>name</code> as a parameter and prints a greeting.</p>



<h4 class="wp-block-heading">Step 2: <strong>Call the Function with an Argument</strong></h4>



<p class="wp-block-paragraph">Now, call the function and pass an argument to the parameter:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
say_hello(&quot;Alice&quot;)

</pre></div>


<p class="wp-block-paragraph">This will output:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Hello, Alice!

</pre></div>


<h4 class="wp-block-heading">Step 3: <strong>Add More Parameters</strong></h4>



<p class="wp-block-paragraph">You can add more parameters to the function to make it more versatile. For example, let’s define a function to calculate the area of a rectangle:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def calculate_area(length, width):
    area = length * width
    return area

</pre></div>


<h4 class="wp-block-heading">Step 4: <strong>Call the Function with Multiple Arguments</strong></h4>



<p class="wp-block-paragraph">Pass multiple arguments to the function:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
result = calculate_area(5, 3)
print(result)  # Output: 15

</pre></div>


<h4 class="wp-block-heading">Step 5: <strong>Use Default Parameters</strong></h4>



<p class="wp-block-paragraph">Let’s add a default value to a parameter. This makes it optional:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def greet_user(username=&quot;Guest&quot;):
    print(f&quot;Hello, {username}!&quot;)

</pre></div>


<p class="wp-block-paragraph">You can call it with or without an argument:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
greet_user()  # Output: Hello, Guest!
greet_user(&quot;Bob&quot;)  # Output: Hello, Bob!

</pre></div>


<h4 class="wp-block-heading">Step 6: <strong>Use Variable-Length Arguments</strong></h4>



<p class="wp-block-paragraph">If you want to accept an arbitrary number of arguments, use <code>*args</code> or <code>**kwargs</code>:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
def add_numbers(*args):
    return sum(args)

print(add_numbers(1, 2, 3, 4))  # Output: 10

</pre></div>


<p class="wp-block-paragraph">This allows you to pass any number of arguments to the function.</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/understanding-parameters-use-cases-architecture-workflow-and-getting-started-guide/">Understanding Parameters: Use Cases, Architecture, Workflow, and Getting Started Guide</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/understanding-parameters-use-cases-architecture-workflow-and-getting-started-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What is the difference between a timeout and an interval in Javascript?</title>
		<link>https://www.scmgalaxy.com/tutorials/what-is-the-difference-between-a-timeout-and-an-interval-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/what-is-the-difference-between-a-timeout-and-an-interval-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Fri, 13 Aug 2021 11:45:42 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[interval ID]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Method]]></category>
		<category><![CDATA[Parameters]]></category>
		<category><![CDATA[setInterval( )]]></category>
		<category><![CDATA[setTimeout()]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7919</guid>

					<description><![CDATA[<p>setTimeout( ) Method The setTimeout() method sets a timer which executes a function or specified piece of code once after [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/what-is-the-difference-between-a-timeout-and-an-interval-in-javascript/">What is the difference between a timeout and an interval in Javascript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading"><strong>setTimeout( ) Method</strong></h2>



<p class="wp-block-paragraph">The setTimeout() method sets a timer which executes a function or specified piece of code once after the timer expires. The function is only executed once. It returns a positive integer value which identifies the timer created by the call to setTimeout(); this value can be passed to clearTimeout() to cancel the timeout.</p>



<p class="wp-block-paragraph">S<strong>yntax: &#8211;<br>setTimeout (function, milliseconds, para1, para2);<br>Ex: &#8211; var timeoutID = setTimeout(show, 2000);</strong></p>



<h2 class="wp-block-heading"><strong>clearTimeout( ) Method</strong></h2>



<p class="wp-block-paragraph">The clearTimeout() method cancels a timeout previously established by calling setTimeout(). The ID value returned by setTimeout() is used as the parameter for the clearTimeout() method.</p>



<p class="wp-block-paragraph"><strong>Syntax: &#8211; clearTimeout (timeoutID);</strong></p>



<p class="wp-block-paragraph"><strong>Ex: &#8211; clearTimeout(timeoutID);</strong></p>



<h2 class="wp-block-heading"><strong>setInterval( ) Method</strong></h2>



<p class="wp-block-paragraph">The setInterval() method repeatedly calls a function or executes a code snippet, with a fixed time delay between each call. It returns an interval ID that uniquely identifies the interval, so you can remove it later by calling clearInterval().</p>



<p class="wp-block-paragraph"><strong>Syntax: &#8211; setInterval (function, milliseconds, para1, para2);</strong></p>



<p class="wp-block-paragraph"><strong>Ex: &#8211; var intervalID = setInterval(show, 2000);</strong></p>



<h2 class="wp-block-heading"><strong>clearInterval( ) Method</strong></h2>



<p class="wp-block-paragraph">The clearInterval() method cancels a timed, repeating action that was previously established by a call to setInterval().</p>



<p class="wp-block-paragraph"><strong>Syntax: &#8211; clearInterval (intervalID);</strong></p>



<p class="wp-block-paragraph"><strong>Ex: &#8211; clearInterval(intervalID);</strong></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/what-is-the-difference-between-a-timeout-and-an-interval-in-javascript/">What is the difference between a timeout and an interval 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/what-is-the-difference-between-a-timeout-and-an-interval-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How does constructor work in JavaScript?</title>
		<link>https://www.scmgalaxy.com/tutorials/how-does-constructor-work-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/how-does-constructor-work-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Tue, 03 Aug 2021 10:22:26 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Parameters]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7307</guid>

					<description><![CDATA[<p>Constructor Object instance are created with constructor, which is basically a special function that prepares a new instance of an [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-does-constructor-work-in-javascript/">How does constructor work in JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Constructor</h2>



<p class="wp-block-paragraph">Object instance are created with constructor, which is basically a special function that prepares a new instance of an object for use.</p>



<script src="https://gist.github.com/vijaypk376/7c4f0358d9ed9b298884b822de90cd25.js"></script>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="768" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/constructor.jpg" alt="" class="wp-image-7310" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/constructor.jpg 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/constructor-300x225.jpg 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/constructor-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">Constructor with Parameter</h2>



<script src="https://gist.github.com/vijaypk376/2c4269caa580e58a122ac08f1e86b849.js"></script>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-does-constructor-work-in-javascript/">How does constructor work 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/how-does-constructor-work-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How does this javascript factorial function work?</title>
		<link>https://www.scmgalaxy.com/tutorials/how-does-this-javascript-factorial-function-work/</link>
					<comments>https://www.scmgalaxy.com/tutorials/how-does-this-javascript-factorial-function-work/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Tue, 03 Aug 2021 10:03:51 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Factory Function]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Parameters]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7305</guid>

					<description><![CDATA[<p>Factory Function When a function returns an object, we call it a factory function. It can produce object instance without [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-does-this-javascript-factorial-function-work/">How does this javascript factorial function work?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Factory Function</h2>



<p class="wp-block-paragraph">When a function returns an object, we call it a factory function. It can produce object instance without <em>new</em> keywords or <em>classes</em>.</p>



<h2 class="wp-block-heading"><strong>Ex:-</strong></h2>



<script src="https://gist.github.com/vijaypk376/aed68402f3f002a5a65aad7e5c2cad11.js"></script>



<h2 class="wp-block-heading">Factory Function with Parameter</h2>



<h2 class="wp-block-heading"><strong>Ex:-</strong></h2>



<script src="https://gist.github.com/vijaypk376/f680fed77d649686f08ca7ad05f3b50c.js"></script>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-does-this-javascript-factorial-function-work/">How does this javascript factorial function work?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/how-does-this-javascript-factorial-function-work/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Object Oriented Programming in JavaScript</title>
		<link>https://www.scmgalaxy.com/tutorials/object-oriented-programming-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/object-oriented-programming-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Mon, 02 Aug 2021 13:01:59 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Operators in PHP]]></category>
		<category><![CDATA[Parameters]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7278</guid>

					<description><![CDATA[<p>Object Oriented Programming Object-oriented programming (OOP) is a programming language model organized around objects rather than &#8220;actions&#8221; and data rather [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/object-oriented-programming-in-javascript/">Object Oriented Programming in JavaScript</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Object Oriented Programming</h2>



<p class="wp-block-paragraph">Object-oriented programming (OOP) is a programming language model organized around objects rather than &#8220;actions&#8221; and data rather than logic.</p>



<h2 class="wp-block-heading">Concepts of OOP</h2>



<ul class="wp-block-list"><li>Encapsulation</li><li>Abstraction</li><li>Inheritance</li><li>Polymorphism</li></ul>



<h2 class="wp-block-heading">Objects</h2>



<p class="wp-block-paragraph">An object is a collection of properties, and a property is an association between a name (or key) and a value. A property&#8217;s value can be a function, in which case the property is known as a method. In addition to objects that are predefined in the browser, you can define your own objects.</p>



<script src="https://gist.github.com/vijaypk376/0824369e547e879562e7656d819a3ddd.js"></script>



<h2 class="wp-block-heading">Type of Objects</h2>



<ul class="wp-block-list"><li>User-defined Objects – These are custom objects created by the programmer to bring structure and consistency to a particular programming task.</li></ul>



<ul class="wp-block-list"><li>Native Objects – These are provided by the JavaScript language itself like String, Number, Boolean, Function, Date, Object, Array, Math, RegExp, Error as well as object that allow creation of user-defined objects and composite types.</li></ul>



<ul class="wp-block-list"><li>Host Objects – These objects are not specified as part of the JavaScript language but that are supported by most host environments, typically browsers like window, navigator.</li></ul>



<ul class="wp-block-list"><li>Document Objects – These are part of the Document Object Model (DOM), as defined by the W3C. These objects presents present the programmer with a structured interface to HTML and XML documents. Access to the document objects is provided by the browser via the document property of the window object (window.document).</li></ul>



<h2 class="wp-block-heading">Declaration and initialization of Object</h2>



<ul class="wp-block-list"><li><strong>Using Object Literal</strong></li></ul>



<script src="https://gist.github.com/vijaypk376/5ad57888a1a5d8f8712a7aca9192c5e4.js"></script>



<p class="wp-block-paragraph">Multiword key required quotation<br></p>



<h2 class="wp-block-heading">Declaration and initialization of Object</h2>



<ul class="wp-block-list"><li><strong>Using Object Literal</strong></li></ul>



<script src="https://gist.github.com/vijaypk376/91b968d68dcbc5c7015d7d59548411ff.js"></script>



<h2 class="wp-block-heading">Declaration and initialization of Object</h2>



<ul class="wp-block-list"><li><strong>Using Object Literal</strong></li></ul>



<script src="https://gist.github.com/vijaypk376/c3bf82f179676fbba47b99e54e34f684.js"></script>



<h2 class="wp-block-heading">Declaration and initialization of Object</h2>



<ul class="wp-block-list"><li><strong>Using Object Constructor</strong></li></ul>



<script src="https://gist.github.com/vijaypk376/a5596079e096a35f2a2b1c9c1bf60c08.js"></script>



<h2 class="wp-block-heading">Declaration and initialization of Object</h2>



<ul class="wp-block-list"><li><strong>Using Object Constructor</strong></li></ul>



<script src="https://gist.github.com/vijaypk376/e7c5a38444b259cc5d0828833469c562.js"></script>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/object-oriented-programming-in-javascript/">Object Oriented Programming 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/object-oriented-programming-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What are arrow functions in JavaScript?</title>
		<link>https://www.scmgalaxy.com/tutorials/what-are-arrow-functions-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/what-are-arrow-functions-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Mon, 02 Aug 2021 12:17:39 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[list with arrows]]></category>
		<category><![CDATA[Parameters]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7250</guid>

					<description><![CDATA[<p>An arrow function expression (previously, and now incorrectly known as fat arrow function) has a shorter syntax compared to function [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/what-are-arrow-functions-in-javascript/">What are arrow functions in JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">An arrow function expression (previously, and now incorrectly known as fat arrow function) has a shorter syntax compared to function expressions. Arrow functions are always anonymous.</p>



<script src="https://gist.github.com/vijaypk376/e122bf9191c5ef70aed54cce4ea37dec.js"></script>



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



<h2 class="wp-block-heading">Arrow Function</h2>



<ul class="wp-block-list"><li>Do not call before definition</li></ul>



<script src="https://gist.github.com/vijaypk376/d2a62c906ae68716afdc945cbc568ed6.js"></script>



<ul class="wp-block-list"><li>An arrow function cannot contain a line break between its parameters and its arrow.</li></ul>



<script src="https://gist.github.com/vijaypk376/e8af1b3f369ca317806d92d746538044.js"></script>



<h2 class="wp-block-heading">Arrow Function With Parameter</h2>



<script src="https://gist.github.com/vijaypk376/53967e3813ce611756bce75ffea7e18a.js"></script>



<p class="wp-block-paragraph">•With one Parameter<br>    Syntax: (para) => {statement};<br>    Syntax: para => {statement};<br>•More than one Parameter<br>    Syntax: (para1, para2, paraN) => {statement};<br>•No Parameter<br>    Syntax: ( ) => {statement};</p>



<h2 class="wp-block-heading">Arrow Function with Parameter</h2>



<script src="https://gist.github.com/vijaypk376/007fe6ea2edde06d21ae790548c37dbc.js"></script>



<p class="wp-block-paragraph">•Default Parameter<br>    Syntax: (para1, para2 = value) => {statement};<br>•Rest Parameter<br>    Syntax: (para1, …args) => {statement};</p>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/what-are-arrow-functions-in-javascript/">What are arrow functions 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/what-are-arrow-functions-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How do I use a default parameter in JavaScript?</title>
		<link>https://www.scmgalaxy.com/tutorials/how-do-i-use-a-default-parameter-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/how-do-i-use-a-default-parameter-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Fri, 30 Jul 2021 13:22:43 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Arguments]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Parameters]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7213</guid>

					<description><![CDATA[<p>Default Parameter Syntax: &#8211;function function_name (para1, para2=“value”, para3) // problem undefined{Block of statement;}Syntax: &#8211;function function_name (para1, para2=“value1”, para3=“value2”){Block of statement;} [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-do-i-use-a-default-parameter-in-javascript/">How do I use a default parameter in JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Default Parameter</h2>



<p class="wp-block-paragraph">Syntax: &#8211;<br>function function_name (para1, para2=“value”, para3) // problem undefined<br>{<br>Block of statement;<br>}<br>Syntax: &#8211;<br>function function_name (para1, para2=“value1”, para3=“value2”)<br>{<br>Block of statement;<br>}</p>



<script src="https://gist.github.com/vijaypk376/b968e96a77da29c151b878bb1229da63.js"></script>



<p class="wp-block-paragraph">JavaScript also allows the use of arrays and null as default values.</p>



<script src="https://gist.github.com/vijaypk376/e477e0661b7216c9e8291c7ae6755cc1.js"></script>



<script src="https://gist.github.com/vijaypk376/93dd055d0136a75a9cdb5e41507f09d9.js"></script>



<h2 class="wp-block-heading">Rest Parameters</h2>



<p class="wp-block-paragraph">The rest parameter allows representing an indefinite number of arguments as an array.</p>



<p class="wp-block-paragraph">Syntax: &#8211;<br>function function_name (…args)<br>   {<br>      Block of statement;<br>   }</p>



<p class="wp-block-paragraph"><br>Syntax: &#8211;<br>function function_name (a, …args)<br>    {<br>      Block of statement;<br>   }</p>



<p class="wp-block-paragraph">The rest operator must be the last parameter to a function.</p>



<h2 class="wp-block-heading">Rest Vs Arguments</h2>



<p class="wp-block-paragraph">There are three main differences between the rest parameters and the arguments object:-</p>



<ul class="wp-block-list"><li>Rest parameters are only the ones that haven&#8217;t been given a separate name, while the arguments object contains all arguments passed to the function.</li><li>The arguments object is not a real array, while Rest Parameters are Array instances, meaning methods like sort, map, forEach or pop can be applied on it directly.</li><li>The arguments object has additional functionality specific to itself (like the callee property).</li></ul>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-do-i-use-a-default-parameter-in-javascript/">How do I use a default parameter 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/how-do-i-use-a-default-parameter-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Write Function in JavaScript?</title>
		<link>https://www.scmgalaxy.com/tutorials/how-to-write-function-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/how-to-write-function-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Fri, 30 Jul 2021 12:56:48 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Arguments]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[javascript function]]></category>
		<category><![CDATA[Parameters]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7198</guid>

					<description><![CDATA[<p>Function Function are subprograms which are used to compute a value or perform a task. Type of Function &#8211; Library [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-to-write-function-in-javascript/">How to Write Function in JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Function</h2>



<p class="wp-block-paragraph">Function are subprograms which are used to compute a value or perform a task.</p>



<h2 class="wp-block-heading"><strong>Type of Function</strong></h2>



<p class="wp-block-paragraph"><strong>&#8211;</strong> <strong>Library or Built-in functions </strong></p>



<p class="wp-block-paragraph">  Ex: &#8211; valueOf( ) , write( ), alert( ) etc</p>



<p class="wp-block-paragraph"><strong>&#8211; User-defined functions</strong></p>



<h2 class="wp-block-heading">Creating and Calling a Function</h2>



<p class="wp-block-paragraph"><strong>Creating a Function</strong></p>



<p class="wp-block-paragraph">Syntax: &#8211;</p>



<p class="wp-block-paragraph">function function_name( )<br>{<br>Block of statement;<br>}</p>



<script src="https://gist.github.com/vijaypk376/802abaf469d88a83f72f42f782c53508.js"></script>



<p class="wp-block-paragraph"><strong>Calling a Function</strong></p>



<p class="wp-block-paragraph">Syntax: &#8211;<br>function_name( );</p>



<p class="wp-block-paragraph">Ex: &#8211;<br>display( );</p>



<h2 class="wp-block-heading">Rules of <strong>Function</strong></h2>



<ul class="wp-block-list"><li>Function name only starts with a letter, an underscore ( _ ).</li><li>Function name cannot start with a number.</li><li>Do not use reserved keywords. e.g. else, if etc.</li><li>Function names are case-sensitive in JavaScript.</li></ul>



<h2 class="wp-block-heading">How Function Call Works</h2>



<p class="wp-block-paragraph">The code inside a function isn‟t executed until that function is called.</p>



<script src="https://gist.github.com/vijaypk376/44b9a36db3935a45075af60b432f6fe9.js"></script>



<h2 class="wp-block-heading">Function with Parameters</h2>



<p class="wp-block-paragraph">Syntax: &#8211;<br>function function_name (parameter1, parameter2, ….)<br>{<br>Block of statement;<br>}</p>



<script src="https://gist.github.com/vijaypk376/f4b2f252018704f3b391618c1447a6f4.js"></script>



<ul class="wp-block-list"><li>JavaScript function definitions do not specify data types for parameters.</li><li>JavaScript functions do not perform type checking on the passed arguments.</li><li>JavaScript functions do not check the number of arguments received.</li></ul>



<h2 class="wp-block-heading">Call Function with Parameter</h2>



<p class="wp-block-paragraph">Syntax: &#8211;<br>function function_name (para1, para2, ….)<br>{<br>Block of statement;<br>}<br>Syntax:-<br>function_name(argument1, argument2);</p>



<script src="https://gist.github.com/vijaypk376/b12dd07ada07e67e83d1408b2c282269.js"></script>



<h2 class="wp-block-heading">Function Argument Missing</h2>



<p class="wp-block-paragraph">If a function is called with missing arguments, the missing values are set to undefined.</p>



<script src="https://gist.github.com/vijaypk376/ec4fb9dc2ceafb3d375b5e894c345f29.js"></script>



<h2 class="wp-block-heading">Arguments Object</h2>



<p class="wp-block-paragraph">The arguments object contains an array of the arguments used when the function was called.<br>This object contains an entry for each argument passed to the function, the first entry&#8217;s index starting at 0. The argument&#8217;s object is not an Array. It is similar to an Array but does not have any Array properties except length.</p>



<script src="https://gist.github.com/vijaypk376/3db52f5e9f1a3facba70da8d707f7749.js"></script>



<h2 class="wp-block-heading">Many Function Arguments</h2>



<p class="wp-block-paragraph">If a function is called with too many arguments, these arguments can be reached using the arguments object which is a built-in.</p>



<script src="https://gist.github.com/vijaypk376/8633149b98995bd061ab2bf000d92ce8.js"></script>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-to-write-function-in-javascript/">How to Write Function 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/how-to-write-function-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Tutorials for PHP Function with Parameters or Arguments</title>
		<link>https://www.scmgalaxy.com/tutorials/tutorials-for-php-function-with-parameters-or-arguments/</link>
					<comments>https://www.scmgalaxy.com/tutorials/tutorials-for-php-function-with-parameters-or-arguments/#respond</comments>
		
		<dc:creator><![CDATA[Ashwani Kumar]]></dc:creator>
		<pubDate>Fri, 23 Jul 2021 13:51:49 +0000</pubDate>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Arguments]]></category>
		<category><![CDATA[Default Values for Function]]></category>
		<category><![CDATA[Default Values for Function parameter]]></category>
		<category><![CDATA[Functions with return values]]></category>
		<category><![CDATA[Parameter passing to Functions]]></category>
		<category><![CDATA[Parameters]]></category>
		<category><![CDATA[Parameters or Arguments]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[PHP Function]]></category>
		<category><![CDATA[PHP Function with Parameters or Arguments]]></category>
		<category><![CDATA[Setting Default Values for Function parameter]]></category>
		<category><![CDATA[Tutorials for PHP Function with Parameters or Arguments]]></category>
		<category><![CDATA[What]]></category>
		<category><![CDATA[What is Function with Parameters or Arguments]]></category>
		<category><![CDATA[Why]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7004</guid>

					<description><![CDATA[<p>What is Function with Parameters or Arguments? The information or variables included within the function&#8217;s parentheses are referred to as [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/tutorials-for-php-function-with-parameters-or-arguments/">Tutorials for PHP Function with Parameters or Arguments</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">What is <strong>Function with Parameters or Argument</strong>s?</h2>



<p class="wp-block-paragraph">The information or variables included within the function&#8217;s parentheses are referred to as parameters. These are used to keep track of values that can be used during runtime. The comma(,) operator allows the user to input as many arguments as he wants. These options are used to accept inputs during runtime. When transferring numbers, such as during a function call, arguments are used. A parameter is a container for parameters that are given to a function. A value supplied to a function is referred to as an argument. In layman&#8217;s terms, both parameter and statement have the same meaning. It&#8217;s crucial to keep in mind that each parameter must be accompanied with an argument.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://w3programmers.com/bangla/wp-content/uploads/2017/10/function-parameter-and-arguments.png" alt="PHP functions,Parameters and arguments"/></figure></div>



<h4 class="wp-block-heading">Syntex:-</h4>



<pre class="wp-block-code"><code>function function_name($first_parameter, $second_parameter) {
    executable code;
}</code></pre>



<p class="wp-block-paragraph"><strong>Example:-</strong> </p>



<script src="https://gist.github.com/AdarshAshwani/4ba710fd954a3ddba47a43187fe99596.js"></script>



<h3 class="wp-block-heading"><strong>Setting Default Values for Function parameter</strong>:-</h3>



<p class="wp-block-paragraph">In PHP, we may define default arguments for function parameters. If no argument is supplied for a parameter with a default value, PHP will call the function with the parameter&#8217;s default specified value.</p>



<script src="https://gist.github.com/AdarshAshwani/c3cab9557310f1bc5004aef9027e262d.js"></script>



<p class="wp-block-paragraph">The default value for the parameter $num in the previous example is 12; if no value is supplied for this parameter in a function call, the default value is used. It&#8217;s also required because the option $str has no default value.</p>



<h3 class="wp-block-heading">Functions with return values:-</h3>



<p class="wp-block-paragraph">Functions can also return values to the portion of the program where they were called. The value is returned to the program section from where it was named using the return keyword. It is possible to return any type of value, including arrays and objects. The return statement also marks the conclusion of the function, stops it from running, and returns the value.</p>



<script src="https://gist.github.com/AdarshAshwani/cbd50f7be8f29fd002eecc1c95a0b60e.js"></script>



<h3 class="wp-block-heading"><strong>Parameter passing to Functions</strong>:-</h3>



<p class="wp-block-paragraph">In PHP, there are two ways to pass an argument to a function.</p>



<p class="wp-block-paragraph"><strong>Pass by Value:–</strong> Moving by value changes the value of an argument within a function, while the original value outside the function stays unaffected. This means that a statement that is a duplicate of the original value is transmitted.</p>



<p class="wp-block-paragraph"><strong>Pass by Reference:</strong>– As statements are passed via proxy, the original value is transmitted. As a result, the starting value has changed. Using the ampersand symbol in pass by reference, we just transmit the value&#8217;s address, where it is kept (&amp;).</p>



<p class="wp-block-paragraph"><strong>Example:-</strong> </p>



<script src="https://gist.github.com/AdarshAshwani/6cd07cd85061dbb4184ed93a1d9fe044.js"></script>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/tutorials-for-php-function-with-parameters-or-arguments/">Tutorials for PHP Function with Parameters or Arguments</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/tutorials-for-php-function-with-parameters-or-arguments/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understand Shell Script Parameters &#8211; Reference</title>
		<link>https://www.scmgalaxy.com/tutorials/shell-script-parameters/</link>
					<comments>https://www.scmgalaxy.com/tutorials/shell-script-parameters/#respond</comments>
		
		<dc:creator><![CDATA[scmgalaxy K]]></dc:creator>
		<pubDate>Fri, 10 Dec 2010 15:18:51 +0000</pubDate>
				<category><![CDATA[Shell Script]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Bash Positional Parameter]]></category>
		<category><![CDATA[Bash shell]]></category>
		<category><![CDATA[bash shell script parameters]]></category>
		<category><![CDATA[Bash Special Parameters]]></category>
		<category><![CDATA[Parameters]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell parameter values]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[shell script arguments example]]></category>
		<category><![CDATA[Shell Script Parameters]]></category>
		<category><![CDATA[Shell Script Parameters Guide]]></category>
		<category><![CDATA[Shell Script Parameters Instructions]]></category>
		<category><![CDATA[Shell Script Parameters Reference]]></category>
		<category><![CDATA[shell script pass parameter]]></category>
		<category><![CDATA[Understand Shell Script Parameters]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/2010/12/10/shell-script-parameters/</guid>

					<description><![CDATA[<p>A parameter is an entity that stores values. It can be a name, a number or some special characters. Bash [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/shell-script-parameters/">Understand Shell Script Parameters &#8211; Reference</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4336" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2010/12/shell-script-parameters.png" alt="shell-script-parameters" width="600" height="400" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2010/12/shell-script-parameters.png 600w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2010/12/shell-script-parameters-300x200.png 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<p><span style="font-size: 9pt; line-height: 115%;">A parameter is an entity that stores values. It can be a name, a number or some special characters. </span></p>
<p class="MsoNormal"><span style="font-size: 9pt; line-height: 115%;">Bash shell provides two kind of parameters.</span></p>
<p class="MsoNormal"><span style="font-size: 9pt; line-height: 115%;">Positional Parameter and Special Parameter</span></p>
<p class="MsoNormal"><strong><em><span style="text-decoration: underline;"><span style="font-size: 9pt; line-height: 115%;">Bash Positional Parameter – $0, $1, $2 ..</span></span></em></strong></p>
<p class="MsoNormal"><span style="font-size: 9pt; line-height: 115%;">Positional parameters are the arguments given to your scripts when it is invoked. It could be from $1 to $N. When N consists of more than a single digit, it must be enclosed in a braces like ${N}.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">The <strong>variable $0 is the basename</strong> of the program as it was called.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">The following example gets two arguments and provides arithmetic operations result between those two integers.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">First, create the arithmetic.sh shell script as shown below.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ cat arithmetic.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">#!/bin/bash</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$1=$1&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$2=$2&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"><br />
</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">let add=$1+$2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">let sub=$1-$2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">let mul=$1*$2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">let div=$1/$2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;Addition=$add\nSubtraction=$sub\nMultiplication=$mul\nDivision=$div\n&#8221;</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">Next, execute the arithmetic.sh with proper parameters as shown below.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ ./arithmetic.sh 12 10</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$1=12</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$2=10</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Addition=22</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Subtraction=2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Multiplication=120</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Division=1</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">In the above output $1 has the value 12, and $2 has 10.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">Shell built-in ‘let’ allows arithmetic operation to be performed on shell variables. The above script does the arithmetic operations such as addition, subtraction, multiplication and division on the given parameters.</span></p>
<p class="MsoNormal" style="line-height: normal;"><strong><em><span style="text-decoration: underline;"><span style="font-size: 9pt;">Set / Unset Bash Positional Parameters</span></span></em></strong></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">The built in set command is used to set and unset the positional parameter.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">First, create the positional.sh shell script as shown below.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ cat positional.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">#!/bin/bash</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"># From command line</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;Basename=$0&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$1=$1&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$2=$2&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$3=$3&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"># From Set builtin</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">set First Second Third</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$1=$1&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$2=$2&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$3=$3&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"># Store positional parameters with -(hyphen)</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">set &#8211; -f -s -t</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$1=$1&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$2=$2&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$3=$3&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"># Unset positional parameter</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">set &#8212;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$1=$1&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$2=$2&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$3=$3&#8221;</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">The above script prints the command line arguments first, then set command sets the positional parameter explicitly. Set with the – refers end of options, all following arguments are positional parameter even they can begin with ‘-’. Set with ‘–’ without any other arguments unset all the positional parameters.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">Next, execute the positional.sh as shown below.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ ./positional.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Basename=positional.sh</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$1=12</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$2=10</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$3=</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$1=First</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$2=Second</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$3=Third</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$1=-f</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$2=-s</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$3=-t</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$1=</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$2=</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$3=<br />
</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="line-height: normal;"><strong><em><span style="text-decoration: underline;"><span style="font-size: 9pt;">Use Bash $* and $@ to Expand Positional Parameters</span></span></em></strong></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">This example shows the value available in <strong>$*</strong> and <strong>$@</strong>.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">First, create the expan.sh as shown below.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ cat expan.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">#!/bin/bash</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">export IFS=&#8217;-&#8216;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">cnt=1</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"># Printing the data available in $*</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo &#8220;Values of \&#8221;\$*\&#8221;:&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">for arg in &#8220;$*&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">do</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> echo &#8220;Arg #$cnt= $arg&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> let &#8220;cnt+=1&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">done</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">cnt=1</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"># Printing the data available in $@</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo &#8220;Values of \&#8221;\$@\&#8221;:&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">for arg in &#8220;$@&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">do</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> echo &#8220;Arg #$cnt= $arg&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> let &#8220;cnt+=1&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">done</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">Next, execute the expan.sh as shown below to see how $* and $@ works.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ ./expan.sh &#8220;This is&#8221; 2 3</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Values of &#8220;$*&#8221;:</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Arg #1= This is-2-3</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Values of &#8220;$@&#8221;:</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Arg #1= This is</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Arg #2= 2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Arg #3= 3</span></em></p>
<p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: Symbol;">· </span><span style="font-size: 9pt;">The above script exported the value of IFS (Internal Field Separator) with the ‘-’.</span></p>
<p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: Symbol;">· </span><span style="font-size: 9pt;">There are three parameter passed to the script expan.sh $1=”This is”,$2=”2″ and $3=”3″.</span></p>
<p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: Symbol;">· </span><span style="font-size: 9pt;">When printing the each value of special parameter “$*”, it gives only one value which is the whole positional parameter delimited by IFS.</span></p>
<p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: Symbol;">· </span><span style="font-size: 9pt;">Whereas “$@” gives you each parameter as a separate word.</span></p>
<p class="MsoNormal" style="line-height: normal;"><strong><em><span style="text-decoration: underline;"><span style="font-size: 9pt;">Use $# to Count Positional Parameters</span></span></em></strong></p>
<p class="MsoNormal" style="line-height: normal;"><strong><span style="font-size: 9pt;">$#</span></strong><span style="font-size: 9pt;"> is the special parameter in bash which gives you the number of positional parameter in decimal.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">First, create the arithmetic.sh as shown below.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ cat arithmetic.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">#!/bin/bash</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">if [ $# -lt 2 ]</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">then</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> echo &#8220;Usage: $0 arg1 arg2&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> exit</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">fi</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$1=$1&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;\$2=$2&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">let add=$1+$2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">let sub=$1-$2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">let mul=$1*$2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">let div=$1/$2</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;Addition=$add\nSubtraction=$sub\nMultiplication=$mul\nDivision=$div\n&#8221;</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">If the number of positional parameters is less than 2, it will throw the usage information as shown below,</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ ./arithemetic.sh 10</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Usage: ./arithemetic.sh arg1 arg2</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><strong><em><span style="text-decoration: underline;"><span style="font-size: 9pt;">Process related Parameters – $$ and $!</span></span></em></strong></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">The special parameter <strong>$$</strong> will give the process ID of the shell. <strong>$!</strong> gives you the process id of the most recently executed background process.</span></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">The following script prints the process id of the shell and last execute background process ID.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ cat proc.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">#!/bin/bash</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;Process ID=$$&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">sleep 1000 &amp;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;Background Process ID=$!&#8221;</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">Now, execute the above script, and check the process id which its printing.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ ./proc.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Process ID=9502</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Background Process ID=9503</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$ ps</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> PID TTY TIME CMD</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> 5970 pts/1 00:00:00 bash</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> 9503 pts/1 00:00:00 sleep</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> 9504 pts/1 00:00:00 ps</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">$</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><strong><em><span style="text-decoration: underline;"><span style="font-size: 9pt;">Other Bash Special Parameters – $?, $-, $_</span></span></em></strong></p>
<p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: Symbol;">· </span><strong><span style="font-size: 9pt;">$?</span></strong><span style="font-size: 9pt;"> Gives the exit status of the most recently executed command.</span></p>
<p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: Symbol;">· </span><strong><span style="font-size: 9pt;">$-</span></strong><span style="font-size: 9pt;"> Options set using set builtin command</span></p>
<p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: Symbol;">· </span><strong><span style="font-size: 9pt;">$_</span></strong><span style="font-size: 9pt;"> Gives the last argument to the previous command. At the shell startup, it gives the absolute filename of the shell script being executed.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ cat others.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">#!/bin/bash</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;$_&#8221;; ## Absolute name of the file which is being executed</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">/usr/local/bin/dbhome # execute the command.</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">#check the exit status of dbhome</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">if [ &#8220;$?&#8221; -ne &#8220;0&#8221; ]; then</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;"> echo &#8220;Sorry, Command execution failed !&#8221;</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">fi</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e &#8220;$-&#8220;; #Set options &#8211; hB</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">echo -e $_ # Last argument of the previous command.</span></em></p>
<p class="MsoNormal" style="line-height: normal;"><span style="font-size: 9pt;">In the above script, the last echo statement “echo -e $_” ($ underscore) also prints hB which is the value of last argument of the previous command. So $_ will give the value after expansion</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><strong><em><span style="font-size: 9pt;">$ ./others.sh</span></em></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">./others.sh</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">/home/oracle</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">Sorry, Command execution failed !</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">hB</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><em><span style="font-size: 9pt;">hB</span></em></p>
<p class="MsoNormal">
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;">
<p class="MsoNormal">
<p>The post <a href="https://www.scmgalaxy.com/tutorials/shell-script-parameters/">Understand Shell Script Parameters &#8211; Reference</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/shell-script-parameters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
