{"id":645,"date":"2024-07-30T19:43:33","date_gmt":"2024-07-30T17:43:33","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=645"},"modified":"2024-07-30T19:43:33","modified_gmt":"2024-07-30T17:43:33","slug":"006-booleans","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/javascript\/javascript-practico\/03-tipos-de-datos-en-javascript\/006-booleans\/","title":{"rendered":"006. Booleans"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Los <strong>valores booleanos<\/strong> solo pueden contener dos valores, <strong><em>TRUE<\/em> <\/strong>o <strong><em>FALSE<\/em><\/strong>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let verdadero = true;\nlet falso = false;\n\nconsole.log(verdadero);\nconsole.log(falso);\nconsole.log(typeof verdadero, typeof falso);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Podemos crear a partir del constructor <strong>Boolean<\/strong>, aunque no es lo suyo.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let ver = new Boolean(true);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">No tiene mucho sentido. La mejor opci\u00f3n es hacerlo literalmente.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Existen valores que no son verdaderos ni falsos, pero que tienden a valores verdaderos o a valores falsos.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(Boolean(0)); \/\/ EL N\u00daMERO 0 TIENDE A FALSO\nconsole.log(Boolean(-4)); \/\/ UN N\u00daMERO NEGATIVO TIENDE A VERDADERO\nconsole.log(Boolean(\"\")); \/\/ CADENA DE TEXTO VAC\u00cdA TIENDE A FALSO\nconsole.log(Boolean(\" \")); \/\/ CUALQUIER CADENA DE TEXTO CON CUALQUIER CAR\u00c1CTER TIENDE A TRUE<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Desde este <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Truthy\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>link<\/strong> <\/a>podemos ver valores que tienden a TRUE y valores que tienden a FALSE.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Un <strong>objeto vac\u00edo<\/strong> tiende a verdadero, un <strong>array<\/strong> tiende a verdadero, un <strong>n\u00famero<\/strong>, <strong>cadena<\/strong>, <strong>infinito<\/strong>&#8230; tienden a verdadero. El valor <strong><em>false<\/em> <\/strong>tiende a falso, el valor <strong><em>null<\/em> <\/strong>tiende a falso, los valores <strong><em>undefined<\/em><\/strong>, 0, <strong><em>NaN<\/em><\/strong>&#8230; tienden a falso.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Los valores booleanos solo pueden contener dos valores, TRUE o FALSE.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":628,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-645","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Sutil Web","author_link":"https:\/\/sutilweb.eu\/index.php\/author\/sutilweb\/"},"uagb_comment_info":0,"uagb_excerpt":"Los valores booleanos solo pueden contener dos valores, TRUE o FALSE.","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/comments?post=645"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/645\/revisions"}],"predecessor-version":[{"id":647,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/645\/revisions\/647"}],"up":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/628"}],"wp:attachment":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/media?parent=645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}