Introduction to JavaScript

cornawakeΛογισμικό & κατασκευή λογ/κού

4 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

58 εμφανίσεις

Introduction to JavaScript

HTML


Hyper Text Markup Language


A set of tags used to define how elements
(text, links, pictures…) will be displayed in a
web page


<html>


<body>

Text that appears in my webpage!

</body>


</html>

What is JavaScript


JavaScript is a scripting language that we will embed in
our HTML Page to make it interactive. JavaScript is an
interpretative language, meaning that it makes all it’s
decisions at runtime and is not pre
-
compiled.


<html>


<body>

<script type=“text/
javascript
”>



document.write(‘Hello

World’);

</script>

</body>


</html>

<script>

This line says we are now going to be using a
scripting language to modify our html page, and we
choose JavaScript. As JavaScript has become the
default script language in browsers, the type tag is
not typically needed anymore.

<script type=“text/
javascript
”>

document.write
(“TEXT”);


This is a JavaScript command for writing text
to a webpage.



The ‘;’ separates different JavaScript
commands.

Extending our Example Further

<html><body>

<script type=“text/
javascript
”>


document.write
(‘<p>Hello World</p><
br
/>’);


document.write
(‘<p>Another</p><
br
/>’);

</script>

</body></html>

Is Equivalent to:

<html>


<body>



<p>Hello World</p><
br
/>



<p>Another</p><
br
/>


</body>

</html>

JavaScript Comments


Comments are used to explain what your
code does


The ‘//’ tells
javaScript

to ignore the line of
text



//The

line below will write hello world

document.write
(‘<p>Hello World</p><
br
/>’)


Comments (cont…)

We can also make multi
-
line comments
with the symbols /* and */



/*

All

3 lines will be ignored


ignoring this


and this

*/

document.write
(‘<p>Hello World</p><
br
/>’);


Comments (cont…)

You can use the ‘//’ to make comments on
the end of lines



document.write
(“hi”); //a

comment


Comments (cont…)

You can use comments to ignore code for
debugging…



/*

Commenting this out because its causing an
error

document.write
(‘<p>Hello World</p><
br
/>’);

*/


Alert


Pops up a message box


Super useful in debugging!


It tells you if you’ve reached a certain line in
your code.


<script type=“text/
javascript
”>


alert(“hello everyone!”);

</script>