Chapter 1
Chapter 1
Chapter 1
Introduction to JavaScript
Objectives
• NCSA Mosaic
– 1993: created at the University of Illinois
– Allowed Web navigation using a graphical user
interface (GUI)
• Netscape Navigator
– 1994: released by Netscape
– Soon controlled 75% of the market
• Microsoft Internet Explorer
– 1996: released by Microsoft
• Server-side scripting
– Scripting language executed from a Web server
– Popular languages: PHP, ASP, JSP
• Can develop interactive Web sites to communicate
with a database
• Server-side scripting language limitations
– Cannot access or manipulate a Web browser
– Cannot run on a client tier
• Basic procedures
– Used for adding JavaScript to Web pages
• Scripts
– JavaScript programs contained within a Web page
• <script> element
– Tells the browser that the scripting engine must
interpret the commands it contains
– Type attribute
• Tells the browser which scripting language and which
version of the scripting language being used
• Object
– Programming code and data
• Treated as an individual unit or component
• Procedures
– Individual statements used in a computer program
grouped into logical units
– Used to perform specific tasks
• Methods
– Procedures associated with an object
• Variables
– Values a program stores in computer memory
• Assigning a value to a variable
– Same as storing a value in a variable
• Identifier
– Name assigned to a variable
– Rules and conventions
• Must begin with an uppercase or lowercase ASCII
letter, dollar sign ($), or underscore ( _ )
• Can use numbers in an identifier: not as the first
character
• Cannot include spaces in an identifier
• Cannot use reserved words for identifiers
• Reserved words (keywords)
– Special words: part of the JavaScript language syntax
JavaScript, Fifth Edition 35
Assigning Variable Names (cont’d.)
• Modifying variables
– Change a variable’s value at any point in a script
• Use a statement including the variable’s name
• Followed by an equal sign
• Followed by the value to assign to the variable
• Expression
– Literal value or variable or a combination of literal
values, variables, operators, and other expressions
• Evaluated by JavaScript interpreter to produce a result
• Operands
– Variables and literals contained in an expression
• Literal
– Value such as a literal string or a number
• Operators
– Symbols used in expressions to manipulate operands
JavaScript, Fifth Edition 42
Understanding Events
• Event
– Specific circumstance monitored by JavaScript
– Script can respond to in some way
– Allows users to interact with Web pages
• Common events: actions users perform
• Can also monitor events not resulting from user
actions
• Validating parser
– Checks for a well formed Web page
– Verifies document conforms to a specific DTD
• Validation
– Process of verifying a well-formed document and
checking the elements in your document
• Web development tools offer validation capabilities
• Validating services found online
– W3C Markup Validation Service:
• http://validator.w3.org
JavaScript, Fifth Edition 52
Writing Valid JavaScript Code