Está en la página 1de 9

0101 "Introduction to js

¿Qué es ECMAscript??
significa el Script de la Asociación Europea de Fabricantes de Computadoras.
al escribir estas instrucciones y decirles a los actores lo que deben decir, podemos determinar cómo debe funcionar nuestra obra.
Entonces, en este caso, usamos nuestro Javascript para decirles a nuestros jugadores o elementos lo que debe hacer Y así es como
funcionan los lenguajes de secuencias de comandos.

102 Java Script Alert


Abrir un archivo en google Chrome para trabajar en Javascript:
primero abres una pestaña nueva en chrome
segundo click derecho(secundario)
tercero "inspeccionar"
cuarto "fuentes"
quinto"fragmentos"

para poder darle instrucciones a js debemos hablar su idioma y encontrar las palabras clave "keywords" adecuadas y correctas para
decirle lo que queremos que haga
¿cómo encuentro las keywords o cómo sabemos cuáles son esas palabras clave?
vamos a dirigirnos a mdn web docs. y seleccionamos javascript.
No! puedes usar o inventar la palabra clave debes usar las que ya tienes en js dentro dela documentación de mdn, palabras que el
navegador conozca
En el caso de las letras “hello” las comillas no es parte de la funcionalidad del código los paréntesis dictan cuál debe ser el mensaje es
decir es un string caracters

103 Data Types

There are other Data Types for example numbers because they have different symbols from the alphabet.
We don’t actually need any special symbols to tell the computer that this is a number… we can just simply type the number.
This data type describes is either true or false
104 Javascript variables
alert("hello");
alert("world");

prompt("what is your name")


I am daniela, and I love my Boñis //and now you commit my information in your memory, the next time you know that my name is
daniela and I love my boñis//
So this is the same reason why we have something called variables in programming in the same way you have committed my name to
your memory.
We can commit pieces of data to the memory of the computer, but first we need to enable the user enter a piece of information

Variable: can remember the information


For example we can write something like “var”
Var myName = “dani” //”dani es string”//

So let’s learn about the PROMPT KEYWORD


prompt that asks the user ‘What is your name?’.
“And now if I hit command enter or control enter on Windows, or simply just click over here, then it will run”

This is what the syntax looks like

105

107. Naming and Naming Conventions for Javascript Variables

Una variable en JavaScript es como una caja en la que puedes guardar cosas que necesitas usar más tarde. Imagina que tienes una
caja en la que puedes guardar tus juguetes favoritos. Cuando quieras jugar con tus juguetes, lo sacas de la caja. De manera similar,
en JavaScript, puedes crear una variable y asignarle un valor (como una palabra o un número) y usarlo más tarde en tu código. Es
como si estuvieras diciéndole a la computadora "guarde esto aquí y luego use esto cuando lo necesite". Así que, en resumen, una
variable en JavaScript es una forma de guardar y usar información en tu programa.
Los nombres de las variables deben comenzar con una letra, un guión bajo (_) o un signo de dólar ($). No deben comenzar con un
número u otro carácter.
Los nombres de las variables pueden contener letras, números, guiones bajos (_) o signos de dólar ($). No deben contener espacios u
otros caracteres especiales.
Los nombres de las variables son sensibles a mayúsculas y minúsculas. "Nombre" y "nombre" son considerados como dos variables
diferentes.
Los nombres de las variables no deben ser palabras clave o palabras reservadas en JavaScript, como if, else, while, for, etc.
Los nombres de las variables deben ser descriptivos y representar el propósito de la variable en el contexto del programa.

Las palabras clave de JavaScript son palabras reservadas que tienen un significado especial en el lenguaje y no se pueden utilizar
como nombres de variables, funciones o clases. Algunas de las palabras clave más comunes en JavaScript son:
let, const, y var: para declarar variables
function: para definir funciones
return: para devolver valores desde funciones
if, else if, y else: para estructuras de control de flujo condicionales
for y while: para estructuras de control de flujo de bucle
switch y case: para estructuras de control de flujo condicionales múltiples
try, catch, y finally: para estructuras de control de excepciones
class, extends, y super: para definir y heredar clases en programación orientada a objetos
import y export: para importar y exportar módulos
Hay más palabras clave en JavaScript, pero estas son algunas de las más comunes que se utilizan en la mayoría de los programas de
JavaScript.

108. String Concatenation

String concatenation is the process of combining two or more strings into a single string. In JavaScript, you can concatenate strings
using the "+" operator.

For example, if you have two strings "Hello" and "world", you can concatenate them like this:

/* Ejemplo 1 Ejemplo 2 Ejemplo 3


*/ varname=DANIELA lettext = "Hello World!"; var tweet = prompt ("compose your tweet")
name.length letlength = text.length; var leng = tweet.length
9 alert("usted ah escrito" + length + alert("usted ah escrito " + leng + " caracteres" + "
"caracteres") usted tiene " + (140 - leng) + " caracteres
>"usted a escrito 12 caracteres" restantes")
caracteres"
109. String Lengths and Retrieving the Number of Characters
String lengths and retrieving the number of characters is an important concept in programming. In JavaScript, a string is a sequence of
characters enclosed in quotation marks, and its length is the number of characters in the string.

To retrieve the length of a string, you can use the built-in length property. For example, if you have a string variable myString, you can
retrieve its length using myString.length. This will return the number of characters in the string.

It's important to note that the length property is not a function, but a property, so you don't need to use parentheses when accessing it.

In addition to retrieving the length of a string, you can also retrieve individual characters from a string by using bracket notation. Each
character in the string is assigned an index, starting from 0 for the first character. For example, if you have a string variable myString,
you can retrieve the first character by using myString[0], the second character by using myString[1], and so on.

It's important to note that attempting to access an index that doesn't exist in the string will result in undefined. It's also important to
remember that strings in JavaScript are immutable, meaning that individual characters cannot be changed directly once the string has
been created.

110. Slicing and Extracting Parts of a String


 In program, a string is a sequence of characters, such as "hello world". Slicing is the process of extracting a portion of a string, while
extracting is the process of accessing a specific part of a string.
To slice a string, you can use square brackets with two indices separated by a colon, like this:


111. Challenge: Changing Casing in Text
I want to show you that you can do with strings is, you can use a method called “toUpperCase()”, that changes all of the
characters in your string to uppercase. So as we have done before, we simply take the variable, and then we write a dot,
and then we use toUpperCase.
So I have a variable that is called name and it contains the string “dani”. Now, if I write name.toUppercase, and then I
add some empty parentheses, and finish off my statement

Escribe algunas funciones que interactúan con el usuario:


Hay varias funciones en JavaScript que interactúan con el usuario, algunas de las más comunes son:
1. prompt: muestra una ventana emergente en el navegador con un mensaje y un campo de entrada de texto, y le pide al
usuario que ingrese un valor.
2. alert: muestra una ventana emergente en el navegador con un mensaje y un botón "Aceptar". Se utiliza para mostrar
información importante al usuario.
3. confirm: muestra una ventana emergente en el navegador con un mensaje y dos botones "Aceptar" y "Cancelar". Se utiliza
para solicitar al usuario una confirmación o respuesta binaria.
4. window.open: abre una nueva ventana en el navegador con una URL específica.
5. console.log: escribe un mensaje en la consola del navegador, que se puede usar para imprimir información para el usuario.
6. document.write: escribe texto directamente en el documento HTML, lo que permite agregar contenido dinámicamente al sitio
web.
7. setTimeout: permite programar una función para que se ejecute después de un período de tiempo específico, lo que puede
usarse para mostrar mensajes o cambiar el contenido en una página después de cierto tiempo.
8. setInterval: permite programar una función para que se ejecute cada cierto período de tiempo, lo que puede usarse para crear
animaciones o actualizar información en tiempo real.
Estas son solo algunas de las funciones más comunes que interactúan con el usuario en JavaScript, pero hay muchas otras
disponibles.

113. Basic Arithmetic and the Modulo Operator in Javascript 


¿Como trabajar con números y javascript? 
 
¿cómo suamas y restas número en javasctipt? 
Sólo con el signo “+” y “-” 

CHALLENGE 

 
 

114. Increment and Decrement Expressions


Now so far what we have seen are all operators that exist in normal mathematics.
But here are some operatores that only exist in programming.

So take a look at this expression.


We create a variable called x and we set it equal to 5.
Then we change the value of x to the previous value, which is 5, plus 1.
So x now equals 6.
Now we've seen this and we've been using this in our previous code.

In most programming languages, instead of writing out “x = x + 1,”


you can simply write “x++”, and, in exactly the same way, x now gets incremented by 1 and is now equal to 6. So x++
115. Functions Part 1: Creating and Calling Functions

this is exactly what functions are. They


allow you to create a series of instructions,
package it into a block of code, and
remember the packaging
The packaging is done by these curly
braces, the opening curly brace specifying
where the series of instructions begins and
the closing curly brace specifying where
that ends, and everything in between is the
block of code that will get executed when
you call this function.
And you also get to give this function a
name. For example in this case it's called
“getMilk”. And this is essentially the structure of how you would create this function for getting milk.

You first start off with a keyword called function that tells the computer that you are constructing, that you are creating
a new function.
We use the function keyword to
say that we're creating a new
function and then we get to give
the function a name to identify
that block of instructions. And
finally we get to put in all the
instructions that we want to be
carried out whenever we call the
function getMilk.
And when we do call the
function getMilk, then all of the
instructions inside that function
will get taken out and executed.

Now the really important thing is to know that there is a


difference between when you create the function,
because this is when you have the function keyword, this
is where you give it a name and where you have the curly
braces that determine what functionality essentially this
function is going to perform.
But when you want to use the function, in programming
we say calling the function, when you call getMilk, then
all you have to write is the name of the function, some
parentheses, and you end the line with a semicolon.

And once you do this, the computer will look to find where this function was created and it will carry out all the
instructions inside the curly braces.

“control + f” para remplazar todas


las “alert” por un “console.log
Now the important difference between the console log and the alert is that the alert is something that the user can see.
So if you had an alert on your web site, then any visitor will be able to see the alert, but the “console.log” are only for
the developer. They only show up in the console, which is not intended for the user. It's meant for the developer to
debug your code, to find out if there were any problems, and to essentially print out parts of the code into the console.

También podría gustarte