Javascript - JavaScript Basics JavaScript 1 Where to Put...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
JavaScript 1 JavaScript Basics
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JavaScript 2 Where to Put Your Scripts • Javascript statements should be enclosed by <script></script> tags, which could be put in either <head> or <body> • Head Section – Scripts that contain functions go in the head section of the document. – It ensures that scripts are loaded before the function is called. – Scripts & variables can be used by elements in an entire web page. <head> <script type="text/javascript"> … JavaScript … </script> </head> <head> <script type="text/javascript"> … JavaScript … </script> </head>
Background image of page 2
JavaScript 3 Where to Put Your Scripts • Body Section – Script placed in the body section are executed. – Execution Order: According to the order presented to the browser – Scripts could be Event driven (discussed later) <script type="text/javascript"> … JavaScript … </script> <script type="text/javascript"> … JavaScript … </script>
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JavaScript 4 Where to Put Your Scripts • External Script – JavaScript are saved in an external text file, with a .js file extension. – Advantages • Allow sharing of code • Easier Maintenance • Search Engine Friendly <script type="text/javascript" src=“… external JS file …” > </script> <script type="text/javascript" src=“… external JS file …” > </script>
Background image of page 4
JavaScript 5 JavaScript Comments • A comment is any text, such as notes, clarifications, and explanations of code. • JavaScript will not interpret comments as script commands. • Single line comment – A line starts with // – Example: // here is a single line comment • Multi-line comment – The /* at the beginning of the line tells JavaScript to ignore everything that follows until the end of the comment */ . – Example: /* Use this method to contain multiple lines of comments */
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JavaScript 6 JavaScript Variables • JavaScript uses variables to store values. • A variable’s value (and type) can change in the script. • Few rules for variable names:- – Begin all variable names with either a letter or underscore(_). – You can then use letter, digits, or underscore for all subsequent characters. – Letters include all uppercase characters (A through Z), and lowercase characters (**case sensitive**). – Digits include the characters 0 through 9. – The sequence of characters should not include any spaces. – No JavaScript reserved words are allowed, including break, export, and this. Reserved words can be found at http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Reserved_Words
Background image of page 6
JavaScript 7 JavaScript Variables • JavaScript does not require specification of data type of a variable. • It automatically converts values of one type to another. • It supports four primitive types:-
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/11/2011 for the course CS 5281 taught by Professor Jianyingwang during the Summer '10 term at City University of Hong Kong.

Page1 / 59

Javascript - JavaScript Basics JavaScript 1 Where to Put...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online