{"id":636,"date":"2024-07-30T19:39:07","date_gmt":"2024-07-30T17:39:07","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=636"},"modified":"2024-07-30T19:39:07","modified_gmt":"2024-07-30T17:39:07","slug":"003-cadenas-de-texto-strings","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/javascript\/javascript-practico\/03-tipos-de-datos-en-javascript\/003-cadenas-de-texto-strings\/","title":{"rendered":"003. Cadenas de texto (Strings)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Antes de comenzar este cap\u00edtulo, una peque\u00f1a nota, si buscamos en google el acr\u00f3nimo <a href=\"https:\/\/developer.mozilla.org\/es\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>MDN<\/strong><\/a>, <strong>MDN<\/strong> es <strong>Mozilla Development Network<\/strong>, que digamos, es la documentaci\u00f3n no oficial que la gente de <a href=\"https:\/\/www.mozilla.org\/es-ES\/firefox\/new\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Mozilla<\/strong><\/a> tiene para nosotros los programadores en <strong>Javascript<\/strong>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">Hay una frase en <strong>Javascript<\/strong> que dice que <strong><em>Todo es un objeto<\/em>. <\/strong>Hasta los tipos m\u00e1s b\u00e1sicos <strong>Javascript<\/strong> (<strong>n\u00fameros<\/strong>, <strong>cadenas<\/strong>, <strong>booleanos<\/strong>, <strong>null<\/strong>, <strong>undefined<\/strong>) son <strong>objetos.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Los <strong>objetos<\/strong> van a tener dos atributos muy importantes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Propiedades<\/strong>: nos van a proporcionar informaci\u00f3n acerca de ese objeto. Son caracter\u00edsticas del objeto. Describen ese objeto.<\/li>\n\n\n\n<li><strong>M\u00e9todos<\/strong>: se trata de acciones que el objeto hace.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">La diferencia entre una <strong>propiedad<\/strong> y un <strong>m\u00e9todo<\/strong> es que los <strong>m\u00e9todos<\/strong> terminan con par\u00e9ntesis, dentro de los cuales pueden recibir ciertos datos para poder trabajar.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Una cadena de texto es un texto encerrado entre <strong>dobles comillas<\/strong> o <strong>comillas simples<\/strong>. No hay ning\u00fan problema entre usar unas u otras comillas, aunque est\u00e1 m\u00e1s estandarizado utilizar la <strong>doble comilla<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Declarar strings<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Existen distintas maneras.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let nombre = \"Francisco\";\nlet apellido = 'Paredes';\nlet saludo = new String(\"Hola Mundo\"); \/\/ No se utiliza<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Veamos un ejm completo.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&nbsp; &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;Strings&lt;\/title&gt;\n&nbsp; &lt;\/head&gt;\n\n&nbsp; &lt;body&gt;\n&nbsp; &nbsp; &lt;script&gt;\n&nbsp; &nbsp; &nbsp; let nombre = \"Franciso\";\n&nbsp; &nbsp; &nbsp; let apellido = \"Paredes\";\n&nbsp; &nbsp; &nbsp; let saludo = new String(\"Hola Mundo\");\n&nbsp; &nbsp; &nbsp; let lorem =\n&nbsp; &nbsp; &nbsp; &nbsp; \" &nbsp; Hola me llamo Francisco Paredes y soy administrador de Sutil Web, \n        Sutil Web es una web de dise\u00f1o y desarrollo web &nbsp; &nbsp;\";\n\n&nbsp; &nbsp; &nbsp; \/\/ USO DE LA PROPIEDAD LENGHT (PROPIEDADES)\n&nbsp; &nbsp; &nbsp; console.log(nombre.length, apellido.length, saludo.length);\n\n&nbsp; &nbsp; &nbsp; \/\/ USO DE LOS M\u00c9TODOS\n&nbsp; &nbsp; &nbsp; \/\/ M\u00c9TODO QUE ESCRIBE TODO EN MAY\u00daSCULAS\n&nbsp; &nbsp; &nbsp; \/\/ includes NOS DICE true O false SI LA PALABRA QUE LE PASAMOS SE REPITE O NO\n&nbsp; &nbsp; &nbsp; \/\/ trim ELIMINA LOS ESPACIOS EN BLANCO QUE APARECEN AL INICIO Y AL FINAL\n&nbsp; &nbsp; &nbsp; \/\/ split GENERA UN ARRAY DE ELEMENTOS, TENEMOS QUE PASARLE UN SEPARADOR\n&nbsp; &nbsp; &nbsp; console.log(\n&nbsp; &nbsp; &nbsp; &nbsp; nombre.toUpperCase(),\n&nbsp; &nbsp; &nbsp; &nbsp; apellido.toUpperCase(),\n&nbsp; &nbsp; &nbsp; &nbsp; lorem.includes(\"Sutil\"),\n&nbsp; &nbsp; &nbsp; &nbsp; lorem.trim(),\n&nbsp; &nbsp; &nbsp; &nbsp; lorem.split(\" \")\n&nbsp; &nbsp; &nbsp; );\n&nbsp; &nbsp; &lt;\/script&gt;\n&nbsp; &lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Antes de comenzar este cap\u00edtulo, una peque\u00f1a nota, si buscamos en google el acr\u00f3nimo MDN, MDN es Mozilla Development Network, que digamos,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":628,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-636","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":"Antes de comenzar este cap\u00edtulo, una peque\u00f1a nota, si buscamos en google el acr\u00f3nimo MDN, MDN es Mozilla Development Network, que digamos,...","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/636","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=636"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/636\/revisions"}],"predecessor-version":[{"id":638,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/636\/revisions\/638"}],"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=636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}