He estado tomando el curso de javascript en https://www.learnstreet.com y me ha parecido bastante bueno. Es un poco parecido al de http://www.codecademy.com/ aunque tiene un nivel más alto y está mejor explicado.
Las explicaciones aparecen en el mismo entorno de trabajo. En codecademy aparecen del lado izquierdo. Aquí la sección del lado izquierdo está más completa y en el Overview se puede desplegar la teoría.
Aquí les pongo el Overview de la sección 3 correspondiente a STRINGS en javasceript:
Lesson 3: Dive
into Strings
What is a String?
A string is a sequence of characters, such as letters, numbers, or other
symbols. They are useful for storing text, website URLs, values for form
fields, and more. To create a string in JS, surround the sequence of characters
using single or double quotes. Note that if you start with a double quote, you
must end it with a double quote. Likewise if using single quotes. The reason JS
allows either to be used is that you can easily define strings that contain
single or double quotes. For example, "i'm a
string" uses double quotes so the single quote can be
used as an apostrophe. If you need to define strings that contain both single
and double quotes, you will need to escape them using the \ escape character, like 'Joe says
"I\'m OK"'.
String Properties
The length of a string is the number of characters it has. You can find out the
length of any string in JS by using the length property. It is one of the very few
properties of JS strings. To access it, use the member (aka dot) . operator on the string, like"LearnStreet".length.
String Methods
JS strings come
with many pre-defined methods. Methods are functions that belong to objects
(both functions and objects will be covered in later sections. Also, don't
worry too much about which terminology to use -- function vs. method, as the
distinction isn't usually important). So string methods are methods that you
can use on any string, using the member (dot)
.
operator, like "the
string".toUpperCase()
. Notice the parentheses after the method name. It
is used to indicate that you are "calling" (running) the function. If
the function takes inputs, you can pass them to the function by placing them
inside the parentheses. If the function accepts more than one input, you
separate the inputs by using a comma (and a space for readability). In the code "the
string".substring(0, 3)
, the 0
and 3
are arguments (values
passed to functions) for thesubstring
method. Note that
these examples use "the string"
as the sample string.
If we store that string in a variable using var myString = "the string";
, we
can call the toUpperCase
on the variable using myString.toUpperCase()
instead.
Before getting into
some of the pre-defined string methods, let's discuss indices first. You can
think of string indices as positions of the characters, except they are 0-based
in JS. Meaning the first character starts at index 0, and the last character is
at index of length - 1. For example, in the string
"Moon"
, 'M' is at index 0, the two 'o's are at indices 1
and 2, and 'n' is at index 3.
Here are some common string
functions JS provide:
- charAt(index) gets the character at the given index.Example: "LearnStreet".charAt(0); returns 'L' and"LearnStreet".charAt(5); returns 'S'.
- substring(start, end) gets the string starting at the startindex and going up to but not including the end index. If theend parameter is left out, it will return a string starting at thestart index and going to the end of the string.Example: "LearnStreet".substring(0, 5); returns "Learn" and"LearnStreet".substring(5); returns "Street".
- indexOf(value) returns the the first index of the specified character or string.Example: "LearnStreet".indexOf("e"); returns 1 because the letter 'e' first occurs at index 1.
- toUpperCase() changes all letters in the string to uppercase.Example: "LearnStreet".toUpperCase(); returns "LEARNSTREET".
Como ven está bastante completo el sitio. Me ha dejado con gran sabor de boca. Igual que en otras escuelas de programación online uno va ganando insignias y puede compartir en redes sociales sus avances.
El último tip viene al final del overview arriba mencionado y es que Mozilla tiene una lista completa de STRING METHODS que conviene ver. El link es el siguiente:
Es todo por hoy; mañana continuaremos.
Buen código.
No hay comentarios:
Publicar un comentario