MODULE2: Functions IN and OUT

Qaybta Xirfada Sayniska iyo iwm

Moderators: Moderators, Junior Moderators

User avatar
afisoone
SomaliNet Super
SomaliNet Super
Posts: 5509
Joined: Wed Jul 22, 2009 9:46 pm
Location: We all want to become president even though Amisom controls Mogadishu

MODULE2: Functions IN and OUT

Post by afisoone »

Salaad subax wanaagsan.

Module2 waxaan rabaa inaa ku sharaxo javascript functions.
In Javascript, they are two types of functions.

1. Declaration function
2. Expression function
1. Declaration function: You can use the function before it is define. Javascript compiler reads declaration at compile time.

Here is an example of declaration function.

Code: Select all

waxQor("we use here before the function is define");

function waxQor(qoraal)
{
	console.log(qoraal);
}
2. Expression function: This function javascript compiler read at run time. That means you use expression only after it is defined. Otherwise you will get e error. Also expression function ends with semicolon in the closing bracket.

here is an example of expression function

Code: Select all

let waxDaabac=(qoraal)=>{
	console.log(qoraal);
};
waxDaabac("we use it after we define the function");
As you can see the expression function has started with variable and it has fat arrow. The fat arrow means it will do something the value in the parenthesis.

Those are the only two type of function in javascript...

let's do more example on the expressions.

You can use two parameters... here is an example of expression function with two parameters.

Code: Select all

let xisaabi=(tiro1, tiro2)=>tiro1+tiro2;
	console.log(xisaabi(5,5));
It will give us `10 after it calculates...

If you want to use more than one line. Always use curly braces to keep them together.. here is an example.

Code: Select all

let xisaabiAndDaabac=(tiro1, tiro2)=>
	{
		let total=tiro1*tiro2;
		console.log(total);
	}
	xisaabiAndDaabac(5,5);

That is all about javascript function.

Now here is the full page.

Code: Select all

<!doctype html>
<html>
<meta charset="utf-8">
<head>
<title>Isticmaalka variableka let</title>
</head>
<body>
<script type="text/javascript">

waxQor("we use here before the function is define");

function waxQor(qoraal)
{
	console.log(qoraal);
}

let waxDaabac=(qoraal)=>{
	console.log(qoraal);
};
waxDaabac("we use it after we define the function");

let xisaabi=(tiro1, tiro2)=>tiro1+tiro2;
	console.log(xisaabi(5,5));

	let xisaabiAndDaabac=(tiro1, tiro2)=>
	{
		let total=tiro1*tiro2;
		console.log(total);
	}
	xisaabiAndDaabac(5,5);



</script>


</body>
</html>

Ok. That is the module 2..


Macalin Afisoone....
  • Similar Topics
    Replies
    Views
    Last post

Return to “Careers - Engineering, Science & Computers”