WHAT IS JAVASCRIPT?
-
Complete programming language except ...
-
Can not open and save files
-
No data types
- Runs in a browser
-
Not compiled
-
No special programs needed
-
Is NOT Java
-
Many scripts available online and in Design Tools Example
JAVASCRIPT CAPABILITIES
WHERE TO ADD SCRIPT
-
Type into Address box of browser.
javascript: alert('hi');document.write('Pretty exciting, huh?')
- Embed within page in the <body> section
<html>
<body>
Hi
<script language = "javascript">
alert('hi')
document.write('<i>Hi again</i>')
</script>
</body>
</html>
- Embed in a page in the <head> section
<head>
<script>
alert("hi")
document.write("hi")
</script>
</head>
-
Link to script in an external file
<script language =
"javascript" src = "myjavascript.js"></script>
SOME DETAILS
-
Java Script is CaSe SeNsItIvE - Alert('hi') is not the same as alert('hi') and
will not work
-
Semi-colons at the end of statements are optional unless more than one statement on
a line.
-
Create comments using
// Only this line
is commented out
/* All of this code is
commented out,
even though it is on different lines */
EXAMPLE
PRACTICE
Experiment with the example above:
- Change the line alert("In head") to Alert("In head") and run the code. Does it work?
- Change the line alert("In head") to alert('In head') and run the code. Does it work?
- Add some text immediately after the <body> tag and run the code. Change the line alert("In head") to document.write("In head"). Run the code. Where is the expression "In head" relative to the text that you typed after the <body> tag?
- Use document.write to write out a hyperlink on the page.
- Add a comment to your <script> code.
SELF-QUIZ