Module2 waxaan rabaa inaa ku sharaxo javascript functions.
1. Declaration function: You can use the function before it is define. Javascript compiler reads declaration at compile time.In Javascript, they are two types of functions.
1. Declaration function
2. Expression function
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);
}
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");
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));
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....