Docsity

JavaScript - Web Programming - Lecture Slides, Slides of Computer Programming

Partial preview of the text

Download JavaScript - Web Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

JavaScript

Part 1

Lecture Overview

 JavaScript background  The purpose of JavaScript  JavaScript syntax

What do we do with

JavaScript?

 A starter list  Adds sizzle to pages (Animation)  Dynamic HTML (DHTML)  Client side data entry validation  Client side CGI  Reduce the load on overburdened servers  Process and manage cookies  Some servers are beginning to support JavaScript  AJAX to load parts of Web pages

What is JavaScript? (1)

 It‟s a programming language that „closely‟ resembles Java  Implementations  European Computer Manufacturers Association created ECMAScript to standardize different scripting versions See ECMA-  I‟ll try to conform  There are others  It‟s a “C ish” language

Creating a First Script

 ****

Creating a First Script

**

**


script tag

Script tag

Script language

Script Placement (2)

 Scripts appearing in a **** tag but outside a procedure execute first in the order they appear  More about procedures later  Code in a procedure is not executed unless explicitly called  Scripts appearing in a **** tag execute as they are encountered  The placement has an effect on page rendering

Handling Java Incapable Browsers

 Include the **** directive to display a message when JavaScript is disabled

**

JavaScript is not enabled.

**

JavaScript Semantics

 Semicolons need not terminate statements although they do no harm  Unless two statements are placed on the same line  Variables  var data type is generic  JavaScript is not strongly typed like Java  Type conversion happens on the fly  Other types  number , boolean , string , function , object

Creating a First Script

(Example)

 See JavaScriptExample1.htm

 Pay particular attention to the order in which the script code executes

Adding Comments

**

**

Variables (1)

 JavaScript is “loosely typed‟  data types change dynamically as the program runs  Declare variables with the var statement

Variables (3)

 Like VB, there are local and global variables  Local variables are declared inside of a procedure  Global variables are declared in a

Functions (Introduction)

 They are the same thing as a VB function or any other programming language function  Functions execute  When called by another procedure  When implemented as an event handler  Event handlers are discussed later