-
-
Save DavidPeralvarez/28d7a6b6eebc71748a4cd5d9be940316 to your computer and use it in GitHub Desktop.
JavaScript - Los objetos envoltorio
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>Curso de Javascript</title> | |
</head> | |
<body> | |
<script src="scripts.js"></script> | |
</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
/* Objetos envoltorio */ | |
var objNumerico = new Number(5), | |
objCadena = new String('Hola'), | |
objBooleano = new Boolean(true); | |
console.log( objNumerico ); | |
console.log( objCadena ); | |
console.log( objBooleano ); | |
console.log( typeof objNumerico ); | |
console.log( typeof objCadena ); | |
console.log( typeof objBooleano ); | |
console.log( objNumerico + 10 ); | |
console.log( objCadena + ' qué tal' ); | |
console.log( objBooleano && true ); | |
console.log( objNumerico.valueOf() ); | |
console.log( objCadena.valueOf() ); | |
console.log( objBooleano.valueOf() ); | |
function queTipoEs( a ){ | |
if ( a instanceof Number ) { | |
console.log( 'Objeto numérico' ); | |
} else if ( a instanceof String ) { | |
console.log( 'Objeto cadena' ); | |
} else if ( a instanceof Boolean ) { | |
console.log( 'Objeto booleano' ); | |
} | |
} | |
queTipoEs( objNumerico ); | |
queTipoEs( objCadena ); | |
queTipoEs( objBooleano ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment