Created
March 19, 2014 15:56
-
-
Save crispamares/9644814 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Plantilla</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains 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
// Ejecuta cada función para analizar los comportamientos | |
// de Javascript que suelen ocasionar errores | |
/* | |
* Ojo 1: Cambiar el tipo de una variable no produce fallo | |
*/ | |
var ojo1 = function() { | |
var numerito = 123; | |
console.log(numerito); | |
numerito = "Hola mundo"; | |
console.log(numerito); | |
return true; | |
}; | |
/* | |
* Ojo 2: Las declaraciones "suben" | |
*/ | |
var ojo2 = function() { | |
console.log("Debería dar un error pero da:", ascensor); | |
var ascensor = "Subo sin valor"; | |
console.log("Ahora tengo valor: " + ascensor); | |
console.log(variableDesconocida); // Esto sí falla | |
return true; | |
}; | |
/* | |
* Ojo 3: El ámbito de las variables es la función no el bloque | |
*/ | |
var ojo3 = function() { | |
console.log("Debería dar un error pero da:", i); | |
for (var i=0; i <= 4; i++) { | |
console.log(i); | |
} | |
console.log("Ya fuera: " + i); | |
return true; | |
}; | |
/* | |
* Ojo 4: Si no pones var la variable se define como global | |
*/ | |
var ojo4 = function() { | |
var f = function(){ | |
global = "Soy global"; | |
var local = "Soy local"; | |
}; | |
f(); | |
console.log( "global: " + global ); | |
console.log( "local: " + local ); | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment