//
/* comentario*/
Salto de línea
‘<br/>’
Var nombre=”jose”;
Manejo de errores
Try{
Catch(e){
Console.log(e)}
escribe en el documento
PI
Math.PI;
Math.E;
Math.floor(numero);
Math.random();
Rondeo de un numero
Math.round(numero)
Valor entero próximo de un numero
Math.ceil(numero);
Raiz cuadrada
Math.sqrt(4)
Potencia
Math.pow(7,2)//49
If-else
If(condicion)
{ } else { }
Switch
switch(nombre){
case "maria":
break;
case "jose":
break;
default:
document.write("no se tu nombre");
break;
Arrays
Días[0]=’lunes’;
Días[1]=’martes ’;
Días[2]=’miercoles’;
Var dias3=[
‘lunes’,’martes’, ‘miercoles’];
Var tamaño=array.length;
Fechas
Cambiar a mayúsculas
Texto.toUpperase();
Cambiar a minúsculas
Texto.toLowerCase();
Insertar en un arreglo
Array.sort();
Texto.indexOf(‘a’);
Texto.lastIndexOf(‘a’);
texto.split(“ ”);
Bucle for
For(i=1;i<6;i++){
}
Funciones (function)//se necesita un botón con id prueba y su onclick=”pruebas()”
function pruebas()
Arreglo.concat([6,7,8,9,10]);
Arreglo.push(6);
Arreglo.unshift(0);
Array.reverse();
Numero.toFixed(2);
window.onload=function(){
var prueba=document.getElementById('prueba');
prueba.addEventListener('click',pruebas,false);
Bucle while
var numer=2;
while(numer<5){
numer++;
Number.(document.getElementById('prueba').value)
ParseInt();
ParseFloat();
10%4=2
Bucle do while
Do{}
While();
Objetos
Var obj={
Numero :10,
Texto:”nuevo texto”,
Objhijo:{
Numero2:20,
Text2:”nuevo texto 2”
}};
Persona.nombre=”pepe”;
Formas de tener control del html
Caja.style.width=”200px”
Var cajas=document.querySelectorAll(“.cajas”)//clase
Document.getElementById(‘parrafo’).innerHTML
Seleccionado. ).style.color=”#ff0000”
Intervalos de tiempo
retardos de tiempo
Settimeout(función(){
Clearinterval(intervalo);
},tiempo)//1000 es un segundo
Instancias
This.color
This.dueno
This.marca}
Pepe.color=”verde”
Pepe.dueño=”pepe”
Pepe.marca=”Toyota”
Mensajes de consola
Console.log(a);
Console.warn(a);
Console.error(a);
Console.info(a);