User Rating: 2 / 5

Star ActiveStar ActiveStar InactiveStar InactiveStar Inactive
 

Functions is a set of commands used in working either . Which runs on the run.

JavaScript Functions Syntax

   Nature of the function is as follows.

function named functions (arguments) .

{ / / Commands } - function names . Naming function is similar to the principle of variable naming . By bestselling author with lowercase. Or if there are multiple words may begin with lowercase letters. The next start with a capital letter such as submitForm (), blockInvalidChar () etc..

  - Arguments (argument) , or the parameter is some information functions required in data processing. This argument is optional , depending on the need .

 

Running the function .

   For me to run the software function , then the function name and arguments  at the point you want to use this function . 

However, the run function , not necessarily in the same <script> tag with the writing function . Or some of the run function can be in HTML tags , but running the function in the HTML tags are mainly caused by the response to certain actions, such as clicking a check . Sainsbury, the characters , etc. 

Example:

<html>
<body>
<p>Click the button to call a function with arguments</p>
<button onclick="myFunction('Spiderman','SuperHero')">Click Here</button>
<script>
function myFunction(name,job)
{alert("Welcome " + name + ", the " + job);}
</script>
</body>
</html>

This is the result:

 

From the above example, when clicking the button. Appears 'welcome Spiderman the SuperHero'.

 

The function returns (Functions With a Return Value). 

    A function return value is created like a normal function. But before the end of the function is used to send commands return some value back out, 

Example:

<html>
<body>
<p id="demo"></p>
<script>
function myFunction(a,b)
{
return a*b;
 }
document.getElementById("demo").innerHTML=myFunction(5,3);
</script>
</body>
</html>

This example calls a function which performs a calculation, and returns the result:

This is the result: 

 

It is evident that the function was being sent back. Which is that it is the answer to a multiple of a and b or 5x3 which is 15 itself. 

    To run the function with the return value. If we want to bring it up to use it to create other variable is the value returned is like.

 

var a = oddorEven (9); // storing the function of the variable a.
var b = oddorEven (10);

 

Function and scope of the variable.

  The scope of the function is defined by { } block , so the declaration or use variables. We must consider the extent of the scope of variables and functions well. 

As follows:

1 . Variables declared in a function (local variable).

Variables declared in a function , it is only available in the function . We were unable to run the variable declared in the function from outside the function , 

for example.

function f () {
var x = 123; 

document.write (x); / / Error! Error occurred because the variable x declared it in the blog function f () function, which at the end of it. Variables such it shall be canceled. We can not refer to variables such.

 

2. Variables that need to be shared (global variable). 

There may be some information that we need to use both in and out of functions. In this case, to create a global variable to store the data. Which variable is to build it outside the function. And not on any such function. 

var ab = 123; 
function f () {
ab + +; / / ok!,}. 
document. write (ab); // 123. 
f (); 
document. write (ab); // 124.

 

 

 

Next

Chapter 10 - JavaScript Operators

Recent Topics
Subject
Post Reply
Open
Recent
Does MD Watermark work under Joomla 3.9.20?
By Balazs Thu 16 Jul 2020 4:48 pm Board English Language
6
148
Thu 16 Jul 2020 10:31 pm By Balazs
The program calculates the PMT
By prmindphp Wed 20 May 2020 6:45 pm Board English Language
1
132
Thu 21 May 2020 5:57 pm By prmindphp
Helper for calculating NPER values
By prmindphp Tue 19 May 2020 6:55 pm Board English Language
1
105
Thu 21 May 2020 5:59 pm By prmindphp
Program that will be used for home loan calculations
By prmindphp Mon 18 May 2020 6:49 pm Board English Language
1
141
Thu 21 May 2020 6:02 pm By prmindphp
Tools that will help calculate car tax
By prmindphp Thu 14 May 2020 7:00 pm Board English Language
1
115
Fri 15 May 2020 12:03 am By prmindphp
Helper to create slidershow, Module Product Slide of MooZiiCart
By prmindphp Thu 30 Apr 2020 6:32 pm Board English Language
0
132
Thu 30 Apr 2020 6:32 pm By prmindphp
Helper in searching products by category and keywords with Module Ajax Search of MooZiiCart
By prmindphp Tue 28 Apr 2020 6:17 pm Board English Language
0
120
Tue 28 Apr 2020 6:17 pm By prmindphp
Helper to restore the system to clear data, Plugin System MRestore
By prmindphp Fri 24 Apr 2020 7:05 pm Board English Language
0
129
Fri 24 Apr 2020 7:05 pm By prmindphp
Creating social share buttons, share the website's content to Social Media With Plugin Content Msocial
By prmindphp Wed 22 Apr 2020 7:05 pm Board English Language
0
127
Wed 22 Apr 2020 7:05 pm By prmindphp
Create Content Marketing and Product with Content Product Match of MooZiiCart
By prmindphp Tue 21 Apr 2020 7:19 pm Board English Language
0
147
Tue 21 Apr 2020 7:19 pm By prmindphp
Filtering for find the product with Module Filter product of MooZiiCart
By prmindphp Thu 09 Apr 2020 6:51 pm Board English Language
0
135
Thu 09 Apr 2020 6:51 pm By prmindphp
Template Megadeal of MooZiiCart for creating websites to sell products online
By prmindphp Fri 03 Apr 2020 6:45 pm Board English Language
0
320
Fri 03 Apr 2020 6:45 pm By prmindphp
Displaying products that customers are interested by Wishlist Module
By prmindphp Fri 27 Mar 2020 5:46 pm Board English Language
0
527
Fri 27 Mar 2020 5:46 pm By prmindphp
Show the Bestsellers Product by Module Bestseller
By prmindphp Wed 25 Mar 2020 6:04 pm Board English Language
0
341
Wed 25 Mar 2020 6:04 pm By prmindphp
Show Products Category by Module Category
By prmindphp Tue 24 Mar 2020 6:07 pm Board English Language
0
383
Tue 24 Mar 2020 6:07 pm By prmindphp
Plugin System MZC Auto Close to enable the open and close odering system
By prmindphp Wed 19 Feb 2020 6:38 pm Board English Language
0
3033
Wed 19 Feb 2020 6:38 pm By prmindphp
MDPartner Component for store client data in CRM system
By prmindphp Sat 25 Jan 2020 3:04 pm Board English Language
0
804
Sat 25 Jan 2020 3:04 pm By prmindphp
i am looking for help
By Anonymous Tue 14 Jan 2020 5:46 pm Board English Language
1
830
Tue 14 Jan 2020 6:03 pm By noppadonsk
Dot Net Training
By Poonaam Fri 10 Jan 2020 2:20 pm Board English Language
0
1051
Fri 10 Jan 2020 2:20 pm By Poonaam
MDRental, Area management assistant for rental business
By prmindphp Wed 08 Jan 2020 6:51 pm Board English Language
0
805
Wed 08 Jan 2020 6:51 pm By prmindphp