Javascript Functions - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Javascript Functions - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Friday, December 30, 2016

Javascript Functions


Javascript Functions


Learn How To Create Functions in Javascript.
Javascript Function are of Four Types :-

a. No Argument With No Return Type
b.No Argument With Return Type
c.Argument With No Return type
d.Argument With return Type

Now Lets Start.

Example of function :-

function hello() // create function hello
{
//body and scope of function
}


1. No Argument With No Return Type

Code : -

<html>
<head>
<script>

function hello() // Create a function hello with no argument
{
console.log( “Calling Function hello”);
}

hello(); // Calling Function hello
// Output : Calling Function Hello in Your Console By Clicking On F12
</script>
</head>
<body>
<h2>Javascript Functions Tutorial</h2>
</body>
</html>

2. No Argument With Return Type

Code : -

<html>
<head>
<script>

function hello() // Create a function hello with no argument
{
var str=“Calling Function hello”;
return str; // Return Value
}

var srt1=hello(); // Calling Function hello Here We Use Echo To Print
console.log(str1); //Because it Only Return Value Not Print it
// Output : Calling Function Hello
</script>
</head>
<body>
<h2>Javascript Functions Tutorial</h2>
</body>
</html>

3. Argument With No Return Type

Code : -

<html>
<head>
<script>

function hello(a) // Create a function hello with argument
{
console.log(a); // Print Value
}

var ab=”hello test”;

hello(ab); // Calling Function hello With Parameter ab
// Output : hello test
</script>
</head>
<body>
<h2>Javascript Functions Tutorial</h2>
</body>
</html>

4. Argument With Return Type

Code : -

<html>
<head>
<script>

function hello(a) // Create a function hello with argument
{
var a=a.toLocaleUpperCase(a);
return a; // Return Value
}

var ab=”hello test”;

var out=hello(ab); // Calling Function hello With Parameter ab
console.log(out); // Output : Hello test Here first letter of word is capital
</script>
</head>
<body>
<h2>Javascript Functions Tutorial</h2>
</body>
</html>
Thank You

No comments:

Post a Comment

Post Top Ad