Docsity

Client Side Programming - Introduction to Java Script - Lecture Slides, Slides of Javascript programming

Partial preview of the text

Download Client Side Programming - Introduction to Java Script - Lecture Slides and more Slides Javascript programming in PDF only on Docsity!

Client-Side Programming:

the JavaScript Language

WWW Structures, Techniques and Standards

JavaScript History and Versions

  • JavaScript was introduced as part of the Netscape 2.0 browser
  • Microsoft soon released its own version called JScript
  • ECMA developed a standard language known as ECMAScript
  • ECMAScript Edition 3 is widely supported and is what we will call

“JavaScript”

JavaScript Introduction

  • File JSHelloWorld.js:
  • HTML document executing this code: script element used to load and execute JavaScript code

JavaScript Introduction

  • Web page and alert box generated by JSHelloWorld.html

document and JSHelloWorld.js code:

JavaScript Properties

  • Note that JavaScript code did not need to be compiled
    • JavaScript is an interpreted language
    • Portion of browser software that reads and executes JavaScript is an interpreter
  • Interpreted vs. compiled languages:
    • Advantage: simplicity
    • Disadvantage: efficiency

JavaScript Properties

  • JavaScript is a scripting language: designed to be executed within a

larger software environment

  • JavaScript can be run within a variety of environments:
    • Web browsers (our focus in next chapter)
    • Web servers
    • Application containers (general-purpose programming)

JavaScript Properties

  • All data in JavaScript is an object or a property of an object
  • Types of JavaScript objects
    • Native: provided by scripting engine
      • If automatically constructed before program execution, known as a built-in object (ex: window)
    • Host: provided by host environment
      • alert and prompt are host objects

Developing JavaScript Software

  • Writing JavaScript code
    • Any text editor ( e.g ., Notepad, Emacs)
    • Specialized software ( e.g ., MS Visual InterDev)
  • Executing JavaScript
    • Load into browser (need HTML document)
    • Browser detects syntax and run-time errors
      • Mozilla: JavaScript console lists errors
      • IE6: Exclamation icon and pop-up window

Developing JavaScript Software

  • IE6 error window: Error indicator; double-clicking icon opens error window Click to see error messages

Developing JavaScript Software

  • Firefox (2.0 and up): the JavaScript console has been renamed “Error

Console” (Tools|Error Console) and shows JavaScript errors, CSS

errors etc…

  • Enhancements available as extensions (e.g. Console 2

, firebug)

  • Chrome (4) has excellent dev support (developer|JavaScript Console)
  • IE8: Tools|Developer tools

Basic JavaScript Syntax

Basic JavaScript Syntax

Notice that there is no main() function/method

Basic JavaScript Syntax

Variable declarations:

  • Not required
  • Data type not specified

Basic JavaScript Syntax

Semi-colons are usually not required, but always allowed at statement end