-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs09-funciones.html
45 lines (42 loc) · 1.2 KB
/
js09-funciones.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<html>
<head>
<title>Ejemplos de funciones anonimas</title>
<script type="text/javascript">
// Function literal notation
// Function object
// Anonymous function
var f1= function(){
alert("Esto es un mensaje");
}
// Funcion anonima con parametros
var f2=function(a,b){
alert("Suma="+(a+b).toString());
}
// Comprueba el resultado cuando falta un parametro f2(4)
// En el caso de que falte un parámetro lo que obtenemos es Suma=NaN
// que significa Not a Number (NaN)
// Funcion anonima con parametros no conocidos
var f3=function(){
var s=0;
for(var i=0;i<arguments.length;i++)
{
s=s+arguments[i];
}
alert("Suma de parametros="+s.toString());
}
// Función que devuelve un valor
var f4=function(a,b){
var c;
c=a-b;
return c;
}
</script>
</head>
<body>
<input type="button" value="Mostrar mensaje" onclick="f1()">
<input type="button" value="Mostrar suma" onclick="f2(5,2)">
<input type="button" value="Mostrar suma con un solo parametro" onclick="f2(5)">
<input type="button" value="Mostrar suma de parametros" onclick="f3(10,20,30,40,50)">
<input type="button" value="Mostrar resta" onclick="alert('Resta='+f4(5,2).toString())">
</body>
</html>