0% found this document useful (0 votes)
33 views

Javascript: Agregar Javascript Al Documento: Head O Body

Javascript can be added to HTML documents in two ways: embedded <script> tags or external .js files linked via <script> tags. Javascript allows accessing and manipulating HTML elements via the DOM, defining functions to encapsulate code, and handling events. It uses common programming concepts like variables, data types, operators, conditional statements and loops.

Uploaded by

Itziar Gallego
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Javascript: Agregar Javascript Al Documento: Head O Body

Javascript can be added to HTML documents in two ways: embedded <script> tags or external .js files linked via <script> tags. Javascript allows accessing and manipulating HTML elements via the DOM, defining functions to encapsulate code, and handling events. It uses common programming concepts like variables, data types, operators, conditional statements and loops.

Uploaded by

Itziar Gallego
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

JAVASCRIPT

Agregar Javascript al documento:


- HEAD O OD!
<script>
function myFunction() {
document.getElementById("demo").innerHTM ! "My First "#$#%cript Function"&
'
<(script>
- HEAD" #I$% E&TER$O
<script src!"my%cript.)s"><(script>
Para acceder a elementos del HT'# desde JavaScript usamos:
- document.getElementById(id)&
#lamar a una (unci)n de JavaScript desde un elemento HT'#
- <*utton onclic+!"myFunction()">Try it<(*utton>
Sinta*is JavaScript
- $+meros: ,.-. / -00- / 1,e2
- String: ""o3n 4oe"
- E*presiones: 256/ -052
- Arra,s: 7.0/ -00/ -/ 2/ 12/ -08
- O-.etos: $#r person !{first9#me:""o3n"/ l#st9#me:"4oe"/ #ge:20/ eye;olor:"*lue"'
- /unciones: function myFunction(#/ *) { return # < *&'
- Varia-les: $#r lengt3& lengt3 ! 6&
- Operaciones: (2 5 6) < -0
- Asignaciones: = ! (> 5 y) < -0&
- Declaraciones: > ! 2 5 6&
- Comentarios:
%imple ?> (( > ! 2 5 6& @ill not *e e>ecuted
Multicoment#rio ?> (< T3e code *eloA Aill c3#nge
t3e 3e#ding Ait3 id ! "myH" <(
- Tipos de datos:
$#r lengt3 ! -6& (( 9um*er #ssigned *y # num*er liter#l
$#r points ! > < -0& (( 9um*er #ssigned *y #n e>pression liter#l
$#r l#st9#me ! ""o3nson"& (( %tring #ssigned *y # string liter#l
$#r c#rs ! 7"%##*"/ "Bol$o"/ "BM@"8& (( Crr#y #ssigned *y #n #rr#y liter#l
$#r person ! {first9#me:""o3n"/ l#st9#me:"4oe"'& (( D*)ect #ssigned *y #n o*)ect
liter#l
Identi(icadores:
*re#+ Termin#tes # sAitc3 or # loop.
c#tc3 M#r+s t3e *loc+ of st#tements to *e e>ecuted A3en #n error occurs in # try *loc+.
continue "umps out of # loop #nd st#rts #t t3e top.
do ... A3ile E>ecutes # *loc+ of st#tements #nd repe#ts t3e *loc+ A3ile # condition is true.
for M#r+s # *loc+ of st#tements to *e e>ecuted #s long #s # condition is true.
for ... in M#r+s # *loc+ of st#tements to *e e>ecuted for e#c3 element of #n o*)ect (or #rr#y).
function 4ecl#res # function.
if ... else M#r+s # *loc+ of st#tements to *e e>ecuted depending on # condition.
return E>its # function.
sAitc3 M#r+s # *loc+ of st#tements to *e e>ecuted depending on different c#ses.
t3roA T3roAs (gener#tes) #n error.
try Implements error 3#ndling to # *loc+ of st#tements.
$#r 4ecl#res # $#ri#*le.
A3ile M#r+s # *loc+ of st#tements to *e e>ecuted A3ile # condition is true.
t,peo( operador:
typeof ""o3n" (( Eeturns string
typeof ,.-. (( Eeturns num*er
typeof f#lse (( Eeturns *oole#n
typeof 7-/1/,/.8 (( Eeturns o*)ect
typeof {n#me:F"o3nF/ #ge:,.' (( Eeturns o*)ect
String" numero" oolean como o-.etos:
$#r > ! neA %tring()& (( 4ecl#res > #s # %tring o*)ect
$#r y ! neA 9um*er()& (( 4ecl#res y #s # 9um*er o*)ect
$#r = ! neA Boole#n()& (( 4ecl#res = #s # Boole#n o*)ect
O-.etos
$#r person ! {first9#me:""o3n"/ l#st9#me:"4oe"/ #ge:20/ eye;olor:"*lue"'&
- Acceder a las propieddes de los o*)etos: person.l#st9#me& (( person7"l#st9#me"8&
- Acceder a los m0todos del o-.eto: n#me ! person.full9#me()&
/unciones
functionName(parameter1, parameter2, parameter3) {
code to be executed
'
- Return:
$#r > ! myFunction(./ ,)& (( Function is c#lled/ return $#lue Aill end up in >
function myFunction(#/ *) {
return # < *& (( Function returns t3e product of # #nd *
'
Varia-les locales: B#ri#*les decl#r#d#s dentro de un# funciGn
function myFunction() {
$#r c#r9#me ! "Bol$o"&
(( code 3ere c#n use c#r9#me
'
Varia-les glo-ales: B#ri#*les decl#r#d#s fuer# de un# funciGn
$#r c#r9#me ! " Bol$o"&
(( code 3ere c#n use c#r9#me
function myFunction() {
(( code 3ere c#n use c#r9#me
'
Eventos:

You might also like