Javascript - JavaScript Basics JavaScript 1 Where to Put Your Scripts Javascript statements should be enclosed by <script><\/script> tags which could be

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

This preview shows page 1 - 9 out of 59 pages.

JavaScript 1 JavaScript Basics
Image of page 1
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>
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>
Image of page 3
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>
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 */
Image of page 5
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
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:- Boolean Float Integer String It also support build-in JavaScript objects , which will be discussed later.
Image of page 7
JavaScript 8 JavaScript Variables • Boolean It supports two literals (conditions): true and false .
Image of page 8
Image of page 9

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

or Head Section Scripts that contain functions go in the head section of the document","course_id":1403166,"doc_date":"2011-01-11T21:08:10-0600","filehash":"14aa870eac3ea0afe08259fd3365ad2fc176595a"},"abtest":{"monetization_uu_mvp_1":0},"featureflags":{"atdCreditCardVerification":false},"isMobile":false}; // LUX // TODO: move this to a global template if want to use `data-lux` on pages // other than the doc page. jQuery('[data-lux]').on('click', function(e) { var el = e.delegateTarget || e.currentTarget; var dataName = el.getAttribute('data-lux'); LUX.addData(dataName, '1'); NREUM.setCustomAttribute(dataName, '1'); });