JavaScript

JS

Características del Lenguaje JavaScript

JS

  • Interpretado
  • Orientado a Objetos
  • Interpretado
  • Débilmente tipado
  • Dinámico

HTML

CSS

SRV

Formas de Implementar

  • Inline
       <button onclick="document.write('holi')">
    
    
  • Interno
       <script>
          document.write('holi');
    ​   </script>
    
    
  • Externo
       <script src="archivo.js"></script>

Sintaxis

  • Comentario de una linea
        // comentario :D
     
  • Comentario de varias líneas
     /* otro
        comentario
        largo */
    
    

Sintaxis

  • Definición de Variables
      var x, y;
    
    
  • Asignación
      x = 3 + 5;
      y = "holi";
      var z = 100, w = 3.14;
      x += 21;   // x = x + 21
      x++;       // x = x + 1
    

Sintaxis

  • Comparadores
      x <  y;   y >  x;
      x <= z;   y >= z;
      x == z;   y != z;
    
    
  • Operadores Lógicos
      true;     false;
      x = x || y;   // OR
      y = x && y;   // AND
      z = !z
    

Sintaxis

Condicionales

if (condicion == true )
  {
    hacer(algo);
  }
else if (condicion2) {
    hacer(otra_cosa);
  }
else { /* nada */ }

Sintaxis

Condicionales

Switch (signo_zodiacal)
{
    case 1:
        nombre = "aries"
        break;

    case 2:
        nombre = "tauro";
        break;

    // otros ...
    default:
        nombre ="no se eligió nada...";
}

Sintaxis: Ciclos

for (i = 0; i <= 100; i++) {
    // algo que hacer
}
var i=0;   // variable de iteración
while (i <= 100) {
    // hacer hasta que i > 100
    i++;
}
var i = 0;
do {
    // hacer al menos una vez hasta i > 100
    i++;
} while (i <= 100)

Sintaxis: Funciones

function promedio(x,y,z) {
    var suma;
    var resultado;
    suma = x+y+z;
    resultado = suma/3;
    return resultado;
}

 

var altura = promedio(10,20,3);
suma = 15; // error!

INteracción Básica

Lectura

variable = prompt("mensaje de entrada");

Escritura

document.write("mensaje");
variable = document.getElementByID("dato").value;
document.getElementByID("dato").value = "mensaje";

POO en JavaScript

Definicion de CLase

Made with Slides.com