SRV
Inline <button onclick="document.write('holi')">
Interno
<script>
document.write('holi');
</script>
Externo <script src="archivo.js"></script>
Comentario de varias líneas
/* otro
comentario
largo */
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
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
if (condicion == true ) { hacer(algo); }
else if (condicion2) {
hacer(otra_cosa);
}
else { /* nada */ }
Switch (signo_zodiacal) { case 1: nombre = "aries" break; case 2: nombre = "tauro"; break; // otros ... default: nombre ="no se eligió nada..."; }
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)
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!
variable = prompt("mensaje de entrada");
document.write("mensaje");variable = document.getElementByID("dato").value;
document.getElementByID("dato").value = "mensaje";