Introducing JavaScript
JavaScript notes on W3Schools.com
(This is self-study tutorial)
Chapter 7 JavaScript
Scripting vs. Programming Languages
A programming language may be used to create
stand-alone programs.
A scripting language is usually built into
a specific application like a database or
spreadsheet or webpage and cannot be used outside
of that application.
Basic Idea of JavaScript
The web page designer adds JavaScript
instructions directly into an HTML source document.
The <script> Element
<script>
alert("Hello, world!")
</script>
Two types of comments
//This is a single-line comment
/* This is a multiple-line
comment */
Making a Web Page Safe for Non-JavaScript Browsers
<script type="text/javascript">
<!--
JavaScript code goes here.....
//-->
</script>
By doing this, non-JavaScript enabled browsers will
ignore everything inside the comments. JavaScript
enabled browsers are smart enough to ignore the
first <!-- but correctly interprets the
following codes.
The free JavaScript codes you download are
often written in such a way to be safe
for non-JavaScript browsers.
However new generation of XML/XHTML browsers
may ignore everything inside comments tags!
Chapter 8 Objects and Variables
The dot Notation
objectName.propertyName
house.color
Object is 'house', its property is 'color'
Assignment Statement
house.color = "green"
The color of the house is green.
Variables
Variables must be declared before used.
<script type="text/javascript">
var answer
answer = 2.3
alert("answer is" + answer)
</script>
The above would create an alert box and
display the text: answer is 2.3.
JavaScript's three types of data
strings, numbers and boolean
If statement
if (booleanPredicate)
{ executeThisIfTrue }
else
{ executeThisIfFalse }