{"id":642,"date":"2024-07-30T19:42:00","date_gmt":"2024-07-30T17:42:00","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=642"},"modified":"2024-07-30T19:42:00","modified_gmt":"2024-07-30T17:42:00","slug":"005-numbers","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/javascript\/javascript-practico\/03-tipos-de-datos-en-javascript\/005-numbers\/","title":{"rendered":"005. Numbers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A diferencia de otros lenguajes donde hay una clasificaci\u00f3n de tipos de datos num\u00e9ricos (<strong>coma flotante<\/strong>, <strong>enteros<\/strong>&#8230;), en <strong>Javascript<\/strong> s\u00f3lo tenemos un tipo de dato <strong>number<\/strong>. La forma de crear variables con valores num\u00e9ricos es la siguiente.<\/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 num = 1;\nlet num2 = new Number(2);\n\nconsole.log(num, num2);<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">operador typeof()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">El operador <strong><em>typeof()<\/em><\/strong> nos dice de qu\u00e9 tipo de dato es una variable.<\/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(typeof num, typeof num2);\n\/\/ NOS INDICA EN CONSOLA EL TIPO DE DATO DE LAS VARIABLES<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Veamos un ejm completo.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"es\"&gt;\n&lt;head&gt;\n&nbsp; &nbsp; &lt;meta charset=\"UTF-8\"&gt;\n&nbsp; &nbsp; &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n&nbsp; &nbsp; &lt;title&gt;Numbers&lt;\/title&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n&nbsp; &nbsp; &lt;h1&gt;Numbers in Javascript&lt;\/h1&gt;\n\n&nbsp; &nbsp; &lt;script&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; let a = 1;\n&nbsp; &nbsp; &nbsp; &nbsp; let b = new Number(2);\n&nbsp; &nbsp; &nbsp; &nbsp; let c = 7.14;\n&nbsp; &nbsp; &nbsp; &nbsp; let d = \"5.6\";\n\n&nbsp; &nbsp; &nbsp; &nbsp; console.log(a);\n&nbsp; &nbsp; &nbsp; &nbsp; console.log(b);\n\n&nbsp; &nbsp; &nbsp; &nbsp; \/\/ toFixed() REDONDEA AL N\u00daMERO DE DECIMALES QUE LE PASEMOS COMO PAR\u00c1METRO\n&nbsp; &nbsp; &nbsp; &nbsp; \/\/ parseInt() DEVUELVE S\u00d3LO LA PARTE ENTERA\n  \n&nbsp; &nbsp; &nbsp; &nbsp; console.log(c.toFixed(1));\n&nbsp; &nbsp; &nbsp; &nbsp; console.log(parseInt(d));\n&nbsp; &nbsp; &nbsp; &nbsp; console.log(typeof c, typeof d);\n&nbsp; &nbsp; &nbsp; &nbsp; console.log(c + parseInt(d));\n&nbsp; &nbsp; &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A diferencia de otros lenguajes donde hay una clasificaci\u00f3n de tipos de datos num\u00e9ricos (coma flotante, enteros&#8230;), en Javascript s\u00f3lo tenemos un&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":628,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-642","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":"A diferencia de otros lenguajes donde hay una clasificaci\u00f3n de tipos de datos num\u00e9ricos (coma flotante, enteros&#8230;), en Javascript s\u00f3lo tenemos un...","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/642","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=642"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/642\/revisions"}],"predecessor-version":[{"id":644,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/642\/revisions\/644"}],"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=642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}