Created
April 10, 2013 01:22
-
-
Save renzocastro/5350996 to your computer and use it in GitHub Desktop.
Javascript: Usos y Tipos de Funciones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('** FUNCIONES **'); | |
console.log('- sin parametros ------------------'); | |
function saludar(){ | |
console.log( arguments ); | |
var mensaje = 'saludar'; | |
console.log(mensaje); | |
} | |
saludar(); | |
saludar('Carlos','Andres'); | |
console.log('- con parametros ------------------'); | |
function despedir(persona){ | |
console.log( arguments ); | |
if( persona === undefined ){ | |
persona = 'nadie'; | |
} | |
var mensaje = 'adios ' + persona; | |
console.log(mensaje); | |
} | |
despedir('Carlos'); | |
despedir(); | |
despedir('Carlos','Andres'); | |
console.log('- sin parametros y usando "arguments" ------------------'); | |
function sumar(){ | |
var resultado = 0; | |
var i; | |
var total = arguments.length; | |
for(i = 0; i<total; ++i){ | |
//resultado = resultado + arguments[i]; | |
resultado += arguments[i]; | |
} | |
console.log(resultado); | |
} | |
sumar(2,4,5,8); | |
sumar(2,34,56,12,235); | |
console.log('- RETORNANDO VALORES ------------------'); | |
function multiplicar(num1, num2){ | |
//var res = num1 * num2; | |
//return res; | |
return num1 * num2; | |
} | |
var m = multiplicar( 2,5 ); | |
console.log( m ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment