Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created April 9, 2020 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidPeralvarez/28d7a6b6eebc71748a4cd5d9be940316 to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/28d7a6b6eebc71748a4cd5d9be940316 to your computer and use it in GitHub Desktop.
JavaScript - Los objetos envoltorio
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
/* 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