JavaScript Programming Chris Seddon

Size: px
Start display at page:

Download "JavaScript Programming Chris Seddon"

Transcription

1 JavaScript Programming Chris Seddon CRS Enterprises Ltd 1

2 CRS Enterprises Ltd 2

3 JavaScript Resources General: ex.html Videos: ZXNyoA?p=douglas+crockford+javascript+the+good+parts&fr=ushvideo&fr2=piv-web Refcardz: Copyright CRS Enterprises Ltd CRS Enterprises Ltd 3

4 History 1992 Oak, Gosling at Sun & FirstPerson 1995 HotJava LiveScript, Eich at Netscape 1996 JScript at Microsoft 1998 ECMAScript Copyright CRS Enterprises Ltd CRS Enterprises Ltd 4

5 Events <button onclick="copytext()">copy Text</button> Attach handlers to elements in the DOM onabort onblur onblur onchange onclick onclick ondblclick ondragdrop onerror onfocus onkeydown onkeypress onkeyup onload onload onmousedown onmousemove onmouseout onmouseover onmouseup onmove onreset onresize onselect onsubmit onunload Copyright CRS Enterprises Ltd CRS Enterprises Ltd 5

6 DOM Objects Built in DOM Objects can be used in the browser Anchor Applet Area Array Boolean Button Checkbox Date Document Event FileUpload Form Frame Function Hidden History Image LayerLink Location Math Navigator Number Object Option Password Radio RegExp Reset Screen Select String Submit Text Textarea Window Copyright CRS Enterprises Ltd CRS Enterprises Ltd 6

7 JavaScript Global Functions Several global funtions available: escape eval isfinite isnan number parsefloat parseint String Taint unescape untaint parsefloat('1.45kg'); // // eval("x=10;y=20;document.write(x*y)"); // // escape(today? or or tomorrow!"); //Today%3F%20tomorrow%21 Copyright CRS Enterprises Ltd CRS Enterprises Ltd 7

8 Data Types Numbers only floating point Strings Booleans Objects name, value pairs prototype inheritance undefined null Copyright CRS Enterprises Ltd CRS Enterprises Ltd 8

9 Numbers Only one number type no integers 64-bit floating point Not exact: = NaN (Not a Number) result of undefined or erroneous operations any arithmetic operation with NaN as an input will have NaN as a result NaN is not equal to anything, including NaN Copyright CRS Enterprises Ltd CRS Enterprises Ltd 9

10 Strings Sequence of 0 or more 16-bit characters immutable single or double quotes No separate character type characters are represented as strings with a length of 1 String to a number It produces NaN if it has a problem var n = Number("5.76") Number to string It stops at the first non-digit character radix can be specified var s = parseint(5.76) Copyright CRS Enterprises Ltd CRS Enterprises Ltd 10

11 Undefined and Null A lot of confusion especially if you use == undefined a variable that has not been assigned default value var var x; x; null an object with no value '' '' == == '0' '0' // // false false 0 == == '' '' // // true true 0 = '0' '0' // // true true false false == == 'false' // // false false false == == '0' '0' // // true true false false == == undefined // // false false false false == == null null // // false false null null == == undefined // // true true " \t\r\n " == == 0 // // true true var var x = null; null; Always compare with === or!== Copyright CRS Enterprises Ltd CRS Enterprises Ltd 11

12 Statements if switch while do for break continue return try/throw Copyright CRS Enterprises Ltd CRS Enterprises Ltd 12

13 Loops Like Java... for(;;) for in while do while for(i for(i = 0; 0; i i < a.length; i++) i++) {{ if(a[i] === === target) break; document.write("..."); }} deep semantics for for (var (var name name in in object) object) {{ if if (object.hasownproperty(name)) {{ document.write("..."); }} }} Copyright CRS Enterprises Ltd CRS Enterprises Ltd 13

14 Switch statement Multiway branch switch value does not need to a number - can be a string case values can be expressions switch switch (favoritemovie) {{ case case "Titanic": alert("not a bad bad choice!"); break; break; case case "Water "Water World": World": alert("no comment"); break; break; case case "Scream 2": 2": alert("it alert("it has has its its moments"); break; break; default default :: alert("i\'m sure sure it it was was great"); great"); }} Copyright CRS Enterprises Ltd CRS Enterprises Ltd 14

15 Exceptions try - throw - catch as in Java Can have a finally clause var var txt; txt; function message() {{ try try {{ f("welcome guest!"); }} catch (err) (err){{ txt txt = "\n\nthere was was an an error error on on this this page."; alert(err + txt); txt); }} }} Copyright CRS Enterprises Ltd CRS Enterprises Ltd 15

16 Try Statement The JavaScript implementation can produce these exception names: 'Error' 'EvalError' 'RangeError' 'SyntaxError' 'TypeError' 'URIError' Copyright CRS Enterprises Ltd CRS Enterprises Ltd 16

17 With statement Intended as a short-hand ambiguous error-prone aaa.bbb.ccc.x = true; true; aaa.bbb.ccc.y = true; true; with with (ooo.eee.oo.ah_ah.ting.tang.walla.walla) {{ x = true; true; y = true; true; }} does this change x and y or aaa.bbb.ccc.x and aaa.bbb.ccc.y Don't use it! Copyright CRS Enterprises Ltd CRS Enterprises Ltd 17

18 Var statement Defines variables within a function. Types are not specified. Initial values are optional. var varname; var varnrerrors = 0; 0; var vara, a, b, b, c; c; Copyright CRS Enterprises Ltd CRS Enterprises Ltd 18

19 Arrays Array inherits from Object indexes are converted to strings and used as names for retrieving values Very efficient for sparse arrays not very efficient in most other cases no need to provide a length or type when creating an array var var a = new new Array(); a[3] a[3] = 300; 300; a[44] = 4400; a[-20] = 2000; a["abc"] = 66; 66; Array length is meaningless for sparse arrays print("array length = "" + a.length); Array Array length length = Copyright CRS Enterprises Ltd CRS Enterprises Ltd 19

20 Array Literals An array literal uses [ ] It can contain any number of expressions, separated by commas mylist = ['oats', 'peas', 'beans']; New items can be appended mylist[mylist.length] = 'barley'; The dot notation should not be used with arrays [ ] is preferred to new Array() Copyright CRS Enterprises Ltd CRS Enterprises Ltd 20

21 Array Methods concat join pop push slice sort splice join two or or more arrays joins the elements of of an an array into a string removes the last element and return it it add new elements to to the end of of an an array returns sub-array sorts elements splice in in new array replacing part of of original Copyright CRS Enterprises Ltd CRS Enterprises Ltd 21

22 Objects No formal definition of a class JavaScript uses objects Objects have properties properties have values properties can be objects with properties no encapsulation (public/private) Prototype Inheritance classical inheritance is not supported Copyright CRS Enterprises Ltd CRS Enterprises Ltd 22

23 Dynamic Objects Unification of Object and hashtable new Object() Hash nature is hidden produces an empty container of name/value pairs members can be accessed with dot notation or subscript notation var var book = new new Object(); book.title = "JavaScript Book"; var var book.chapter1 = new new Object(); book.chapter1.title = "Chapter 1"; 1"; book.chapter1.pages = 23; 23; Copyright CRS Enterprises Ltd CRS Enterprises Ltd 23

24 Creating Objects Make a new empty object {} is the preferred form. var varp1 p1 = new newobject(); var varp2 p2 = {{}; }; Creating populated objects var var p1 p1 = new new Object(); p1.x p1.x = 44; 44; p1.y p1.y = 45; 45; var var p2 p2 = {'x': {'x': 54, 54, 'y': 'y': 55}; 55}; Copyright CRS Enterprises Ltd CRS Enterprises Ltd 24

25 Accessing Objects Create object: var var p1 p1 = {'x': {'x': 44, 44, 'y': 'y': 55}; 55}; Attributes can be accessed using [ ] or dot notation: document.write(p1['x'], p1['y'); document.write(p1.x, p1.y); Members can be removed from an object with the delete operator: delete p1['x'] Copyright CRS Enterprises Ltd CRS Enterprises Ltd 25

26 Object Literals Can be nested... var var myobject = {{ name: name: "Jack "Jack B. B. Nimble", 'goto': 'goto':'jail', 'Jail', grade: grade: 'A', 'A', format: {{ type: type: 'rect', 'rect', width: width: 1920, 1920, height: height: 1080, 1080, interlace: false, false, framerate: }} }; }; Copyright CRS Enterprises Ltd CRS Enterprises Ltd 26

27 Prototype Inheritance... JavaScript use prototype inheritance unfamiliar to classical programmers object inheritance, not class inheritance An object can inherit from an older object prototype property defines linkage Copyright CRS Enterprises Ltd CRS Enterprises Ltd 27

28 ... Prototype Inheritance function Rectangle(h, w) w) {{ function NamedRectangle(h, w, w, name) name) {{ this.h this.h = h; h; this.prototype = Rectangle; this.w this.w = w; w; this.prototype(h, w); w); this.area = function() {{ this.name = name; name; return return this.h this.h ** this.w; this.w; }} }; }; }} var var p1 p1 = new new Rectangle(7, 8); 8); var var area area = p1.area(); print(area); var var p2 p2 = new new NamedRectangle(3, 6, 6, "small"); area area = p2.area(); print(area); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 28

29 Extension Methods Prototype inheritance allows addition of methods to existing classes String.prototype.sayHello = function() {{ print("hello to to "" + this); }; }; "Chris".sayHello(); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 29

30 Arrays v Objects Arrays are implemented as hash tables not continguous memory Use arrays when the names are sequential integers length property makes sense Use objects when the names are arbitrary strings using arrays in this situation can be confusing Copyright CRS Enterprises Ltd CRS Enterprises Ltd 30

31 Arrays and Inheritance Don t use arrays as prototypes. The object produced this way does not have array nature. It will inherit the array's values and methods, but not its length. You can augment an individual array. Assign a method to it. This works because arrays are objects. You can augment all arrays. Assign methods to Array.prototype Copyright CRS Enterprises Ltd CRS Enterprises Ltd 31

32 Reference Objects can be passed as arguments to functions, and can be returned by functions Objects are passed by reference. Objects are not passed by value. The === operator compares object references, not values true only if both operands are the same object Copyright CRS Enterprises Ltd CRS Enterprises Ltd 32

33 Function Objects... Functions are objects so they can contain name/value pairs can serve the same purpose as static members in other languages no implicit type checking on the arguments If a function is called with too many arguments extra arguments are ignored If a function is called with too few arguments the missing values will be undefined Copyright CRS Enterprises Ltd CRS Enterprises Ltd 33

34 ... Defining Function Objects Three different ways to define functions: 1. function sayhello(arg1,arg2) {{ // // function content content goes goes here here }} 2. var var sayhello = function(arg1,arg2) {{ // // function content content goes goes here here }; }; 3. var var sayhello = new new Function("arg1", "arg2", "arg2","print(arg1, arg2"); arg2"); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 34

35 Methods... Since functions are values, functions can be stored in objects a function in an object is called a method. var var myobject = {{ value: value: 0, 0, increment: function (inc) (inc){{ if(typeof inc inc === === 'number') {{ this.value += += inc; inc; }} else else {{ this.value += += 1; 1; }} }} }; }; myobject.increment(2); print(myobject.value); myobject.increment(); print(myobject.value); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 35

36 ... Methods Variations on the method pattern: var var myobject = function() {{ return return {{ anonymous object hello hello ::"Hello", "Hello", saygoodbye :: function() {{ print("goodbye"); }} }; }; }(); }();//// execute and and return return immediately print(myobject.hello); myobject.saygoodbye(); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 36

37 Arguments When a function is invoked, in addition to its parameters, it also gets a special parameter called arguments. it contains all of the arguments from the invocation an array-like object function sum() sum() {{ var var total total = 0; 0; for for (var (var i i = 0; 0; i i < arguments.length; i i += += 1) 1) {{ total total += += arguments[i]; }} return return total; total; }} var var result result = sum(6, sum(6, 4, 4, 9, 9, 3, 3, 7, 7, 2); 2); print(result); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 37

38 More on Functions Scope {blocks} do not have scope only functions have scope. vars defined in a function are not visible outside of the function Return statement if there is no expression, then the return value is undefined except for constructors, whose default return value is this Inner functions functions can be nested Copyright CRS Enterprises Ltd CRS Enterprises Ltd 38

39 Closure The scope of an inner function continues even after the parent functions have returned This is called closure var var v = function() {{ var var hello hello = "Hello"; "Hello"; var var saygoodbye = function() {{ print("goodbye"); }; }; var var obj obj = {{ a :: hello, hello, b :: function() {{ print(hello); saygoodbye(); }} }; }; return return obj; obj; }(); }();//// execute and and return return immediately print(v.a); v.b(); v.b(); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 39

40 Comparison == and!== use type coercion with confusing results don't use === and!=== don't use coercion sensible results value = myobject[name] if(value == == null) null) {{ alert(name + '' not not found') }} bad value = myobject[name]; if(value === === undefined) {{ alert(name + '' not not found'); }} good Copyright CRS Enterprises Ltd CRS Enterprises Ltd 40

41 Style Matters Be careful with { } use Java style braces problems with optional semicolons return return {{ ok: ok: false false }; }; return return ;; {{ ok: ok: false false ;; }; }; wrong return return {{ ok: ok: false false ;; }; }; return return {{ ok: ok: false; false; }} correct Always insert semi-colons Copyright CRS Enterprises Ltd CRS Enterprises Ltd 41

42 Crockford's JavaScript Toolkit Look at Douglas Crockford's Remedial JavaScript Contains a small, but useful toolkit of JavaScript functions var var template = '<table '<table border="{border}">' + '<tr><th>last</th><td>{last}</td></tr>' + '<tr><th>first</th><td>{first}</td></tr>' + '</table>'; var var data data = {{ first: first: "Carl", "Carl", last: last: "Hollywood", border: 2 }; }; mydiv.innerhtml = template.supplant(data); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 42

43 Global Variables are Dangerous Functions within an application can clobber each other Cooperating applications can clobber each other Use of the global namespace must be minimized Copyright CRS Enterprises Ltd CRS Enterprises Ltd 43

44 Implied Global Any var which is not properly declared is assumed to be global by default This makes it easy for people who do not know or care about encapsulation to be productive but it makes applications less reliable. JSLint is a tool which helps identify implied globals and other weaknesses Copyright CRS Enterprises Ltd CRS Enterprises Ltd 44

45 Namespace Every object is a separate namespace use an object to organize your variables and functions var var AMADEUS = {}; {}; display display = function(o) function(o) {{ for(key for(key in in o) o) {{ document.write(key, ":", ":", o[key]); o[key]); }} }; }; AMADEUS.myObject = {{ x:200, y:500 }; }; display(amadeus.myobject); Copyright CRS Enterprises Ltd CRS Enterprises Ltd 45

46 Encapsulate Function scope can create an encapsulation must use an anonymous function to wrap your application This works identifier optional (function(){ alert(2 alert(2 + 2); 2); })(); })(); FunctionExpression :: function Identifieropt (FormalParameterListopt) {FunctionBody} This fails to compile identifier mandatory function(){ alert(2 alert(2 + 2); 2); }(); }(); FunctionDeclaration :: function Identifier (( FormalParameterListopt )){FunctionBody} Copyright CRS Enterprises Ltd CRS Enterprises Ltd 46

47 RegExp Regular expression pattern matcher var var parse_number = RegExp( "^" "^" + // // start start of of line line "-?" "-?" + // // optional -- "\\d+" "\\d+" + // // digits digits "(?:\\.\\d*)?" + // //.. digits digits "(?:e[+\\-]?\\d+)?" + // // optional exponent "$","i"); "$","i"); // // end end of of line line "$", "$", // // end end of of line line "i"); "i"); // // ignore ignore case case var var test test = function (n) (n){{ print(parse_number.test(n)); }; }; Copyright CRS Enterprises Ltd CRS Enterprises Ltd 47

48 Threads The language definition is neutral on threads Some language processors e.g. SpiderMonkey provide thread support Most application environments e.g. browsers do not provide thread support Server side engines support threading e.g Java Virtual Machine Copyright CRS Enterprises Ltd CRS Enterprises Ltd 48

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Program Structure function sqr(i) var result; // Otherwise result would be global. result = i * i; //

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Program Structure function sqr(i) var result; // Otherwise result would be global. result = i * i; //

More information

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli LECTURE-2 Functions review HTML Forms Arrays Exceptions Events 1 JAVASCRIPT FUNCTIONS, REVIEW Syntax function (params) { // code Note: Parameters do NOT have variable type. 1. Recall: Function

More information

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli LECTURE-3 Exceptions JS Events 1 EXCEPTIONS Syntax and usage Similar to Java/C++ exception handling try { // your code here catch (excptn) { // handle error // optional throw 2 EXCEPTIONS EXAMPLE

More information

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8 INDEX Symbols = (assignment operator), 56 \ (backslash), 33 \b (backspace), 33 \" (double quotation mark), 32 \e (escape), 33 \f (form feed), 33

More information

Client-Side Web Technologies. JavaScript Part I

Client-Side Web Technologies. JavaScript Part I Client-Side Web Technologies JavaScript Part I JavaScript First appeared in 1996 in Netscape Navigator Main purpose was to handle input validation that was currently being done server-side Now a powerful

More information

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications JavaScript Started as a simple script in a Web page that is interpreted and run by the browser Supported by most modern browsers Allows dynamic update of a web page More generally, allows running an arbitrary

More information

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications JavaScript Started as a simple script in a Web page that is interpreted and run by the browser Supported by most modern browsers Allows dynamic update of a web page More generally, allows running an arbitrary

More information

Such JavaScript Very Wow

Such JavaScript Very Wow Such JavaScript Very Wow Lecture 9 CGS 3066 Fall 2016 October 20, 2016 JavaScript Numbers JavaScript numbers can be written with, or without decimals. Extra large or extra small numbers can be written

More information

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming Handling s In JavaScript In programing, event-driven programming could be a programming paradigm during which the flow of the program is set by events like user actions (mouse clicks, key presses), sensor

More information

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview CISH-6510 Web Application Design and Development Overview of JavaScript Overview What is JavaScript? History Uses of JavaScript Location of Code Simple Alert Example Events Events Example Color Example

More information

Fundamentals of Website Development

Fundamentals of Website Development Fundamentals of Website Development CSC 2320, Fall 2015 The Department of Computer Science Events handler Element with attribute onclick. Onclick with call function Function defined in your script or library.

More information

CSC Web Programming. Introduction to JavaScript

CSC Web Programming. Introduction to JavaScript CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

More information

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript Lecture 3: The Basics of JavaScript Wendy Liu CSC309F Fall 2007 Background Origin and facts 1 2 Needs for Programming Capability XHTML and CSS allows the browser to passively display static content How

More information

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p. Preface p. xiii Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p. 5 Client-Side JavaScript: Executable Content

More information

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation

More information

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives New Perspectives on Creating Web Pages with HTML Tutorial 9: Working with JavaScript Objects and Events 1 Tutorial Objectives Learn about form validation Study the object-based nature of the JavaScript

More information

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Visit us on the World Wide Web at: www.pearsoned.co.uk Pearson Education Limited 2014

More information

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation

More information

JavaScript: The Good Parts

JavaScript: The Good Parts JavaScript: The Good Parts The World's Most Misunderstood Programming Language Douglas Crockford Yahoo! Inc. A language of many contrasts. The broadest range of programmer skills of any programming language.

More information

JavaScript: The Good Parts. Douglas Crockford Yahoo! Inc.

JavaScript: The Good Parts. Douglas Crockford Yahoo! Inc. JavaScript: The Good Parts Douglas Crockford Yahoo! Inc. http://www.crockford.com/codecamp/ The World's Most Popular Programming Language The World's Most Popular Programming Language The World's Most

More information

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM) Page 1 HTML User Interface Controls CSE 190 M (Web Programming), Spring 2007 University of Washington Reading: Sebesta Ch. 5 sections 5.1-5.7.2, Ch. 2 sections 2.9-2.9.4 Interactive HTML user interfaces

More information

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language? Why Discuss JavaScript? CS312: Programming Languages Lecture 21: JavaScript Thomas Dillig JavaScript is very widely used and growing Any AJAX application heavily relies on JavaScript JavaScript also has

More information

CS312: Programming Languages. Lecture 21: JavaScript

CS312: Programming Languages. Lecture 21: JavaScript CS312: Programming Languages Lecture 21: JavaScript Thomas Dillig Thomas Dillig, CS312: Programming Languages Lecture 21: JavaScript 1/25 Why Discuss JavaScript? JavaScript is very widely used and growing

More information

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies Internet t Software Technologies JavaScript part one IMCNE A.A. 2008/09 Gabriele Cecchetti Why introduce JavaScript To add dynamicity and interactivity to HTML pages 2 What s a script It s a little interpreted

More information

Events: another simple example

Events: another simple example Internet t Software Technologies Dynamic HTML part two IMCNE A.A. 2008/09 Gabriele Cecchetti Events: another simple example Every element on a web page has certain events which can trigger JavaScript functions.

More information

JavaScript: Sort of a Big Deal,

JavaScript: Sort of a Big Deal, : Sort of a Big Deal, But Sort of Quirky... March 20, 2017 Lisp in C s Clothing (Crockford, 2001) Dynamically Typed: no static type annotations or type checks. C-Like Syntax: curly-braces, for, semicolons,

More information

JavaScript Introduction

JavaScript Introduction JavaScript Introduction Web Technologies I. Zsolt Tóth University of Miskolc 2016 Zsolt Tóth (UM) JavaScript Introduction 2016 1 / 31 Introduction Table of Contents 1 Introduction 2 Syntax Variables Control

More information

TEXTAREA NN 2 IE 3 DOM 1

TEXTAREA NN 2 IE 3 DOM 1 778 TEXTAREA Chapter 9DOM Reference TEXTAREA NN 2 IE 3 DOM 1 The TEXTAREA object reflects the TEXTAREA element and is used as a form control. This object is the primary way of getting a user to enter multiple

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Introduction to DHTML

Introduction to DHTML Introduction to DHTML HTML is based on thinking of a web page like a printed page: a document that is rendered once and that is static once rendered. The idea behind Dynamic HTML (DHTML), however, is to

More information

DC71 INTERNET APPLICATIONS JUNE 2013

DC71 INTERNET APPLICATIONS JUNE 2013 Q 2 (a) With an example show text formatting in HTML. The bold text tag is : This will be in bold. If you want italics, use the tag, as follows: This will be in italics. Finally, for

More information

Node.js Training JavaScript. Richard richardrodger.com

Node.js Training JavaScript. Richard richardrodger.com Node.js Training JavaScript Richard Rodger @rjrodger richardrodger.com richard.rodger@nearform.com A New Look at JavaScript Embracing JavaScript JavaScript Data Structures JavaScript Functions Functional

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Client vs Server Scripting

Client vs Server Scripting Client vs Server Scripting PHP is a server side scripting method. Why might server side scripting not be a good idea? What is a solution? We could try having the user download scripts that run on their

More information

Lecture 8 (7.5?): Javascript

Lecture 8 (7.5?): Javascript Lecture 8 (7.5?): Javascript Dynamic web interfaces forms are a limited interface

More information

INF5750. Introduction to JavaScript and Node.js

INF5750. Introduction to JavaScript and Node.js INF5750 Introduction to JavaScript and Node.js Outline Introduction to JavaScript Language basics Introduction to Node.js Tips and tools for working with JS and Node.js What is JavaScript? Built as scripting

More information

Want to add cool effects like rollovers and pop-up windows?

Want to add cool effects like rollovers and pop-up windows? Chapter 10 Adding Interactivity with Behaviors In This Chapter Adding behaviors to your Web page Creating image rollovers Using the Swap Image behavior Launching a new browser window Editing your behaviors

More information

JavaScript. What s wrong with JavaScript?

JavaScript. What s wrong with JavaScript? JavaScript 1 What s wrong with JavaScript? A very powerful language, yet Often hated Browser inconsistencies Misunderstood Developers find it painful Lagging tool support Bad name for a language! Java

More information

Advanced Topics in Programming Languages Spring Semester, Lecture 2: March 13, JavaScript

Advanced Topics in Programming Languages Spring Semester, Lecture 2: March 13, JavaScript Advanced Topics in Programming Languages Spring Semester, 2012 Lecture 2: March 13, 2012 Lecturer: Prof. Mooly Sagiv Scribe: Omri Gindi and Roi Becker JavaScript 2.1 General JavaScript is a language with

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 1 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) WHO

More information

Basics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript

Basics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript Basics of JavaScript History of the Web XHTML CSS Last Week Nan Niu (nn@cs.toronto.edu) CSC309 -- Fall 2008 2 Needs for Programming Capability XHTML and CSS allows the browser to passively display static

More information

CSC Javascript

CSC Javascript CSC 4800 Javascript See book! Javascript Syntax How to embed javascript between from an external file In an event handler URL - bookmarklet

More information

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting. What is JavaScript? HTML and CSS concentrate on a static rendering of a page; things do not change on the page over time, or because of events. To do these things, we use scripting languages, which allow

More information

Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages

Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages Javascript Key features Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages (DHTML): Event-driven programming model AJAX Great example: Google Maps

More information

JavaScript for PHP Developers

JavaScript for PHP Developers JavaScript for PHP Developers Ed Finkler @funkatron coj@funkatron.com May 18, 2010 #tekx #js4php http://joind.in/1564 What is this? 2 A practical overview of JS for the PHP developer Stop c+p'ing, start

More information

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore JavaScript and XHTML Prof. D. Krupesha, PESIT, Bangalore Why is JavaScript Important? It is simple and lots of scripts available in public domain and easy to use. It is used for client-side scripting.

More information

Session 6. JavaScript Part 1. Reading

Session 6. JavaScript Part 1. Reading Session 6 JavaScript Part 1 Reading Reading Wikipedia en.wikipedia.org/wiki/javascript Web Developers Notes www.webdevelopersnotes.com/tutorials/javascript/ JavaScript Debugging www.w3schools.com/js/js_debugging.asp

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning.

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning. 2017 International Conference on Computer, Electronics and Communication Engineering (CECE 2017) ISBN: 978-1-60595-476-9 XSS Vulnerability Scanning Algorithm Based on Anti-filtering Rules Bo-wen LIU 1,

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

JScript Reference. Contents

JScript Reference. Contents JScript Reference Contents Exploring the JScript Language JScript Example Altium Designer and Borland Delphi Run Time Libraries Server Processes JScript Source Files PRJSCR, JS and DFM files About JScript

More information

CGS 3066: Spring 2015 JavaScript Reference

CGS 3066: Spring 2015 JavaScript Reference CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within

More information

Canvas & Brush Reference. Source: stock.xchng, Maarten Uilenbroek

Canvas & Brush Reference. Source: stock.xchng, Maarten Uilenbroek Canvas & Brush Reference Source: stock.xchng, Maarten Uilenbroek Canvas Hierarchy WACanvas WAHtmlCanvas WARenderCanvas WAStaticHtmlCanvas Brush Hierarchy WABrush WACompound WADateInput WATimeInput WATagBrush

More information

Boot Camp JavaScript Sioux, March 31, 2011

Boot Camp JavaScript  Sioux, March 31, 2011 Boot Camp JavaScript http://rix0r.nl/bootcamp Sioux, March 31, 2011 Agenda Part 1: JavaScript the Language Short break Part 2: JavaScript in the Browser History May 1995 LiveScript is written by Brendan

More information

JSF - H:INPUTSECRET. Class name of a validator that s created and attached to a component

JSF - H:INPUTSECRET. Class name of a validator that s created and attached to a component http://www.tutorialspoint.com/jsf/jsf_inputsecret_tag.htm JSF - H:INPUTSECRET Copyright tutorialspoint.com The h:inputsecret tag renders an HTML input element of the type "password". JSF Tag

More information

Working with JavaScript

Working with JavaScript Working with JavaScript Creating a Programmable Web Page for North Pole Novelties 1 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page 2 Objectives

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 2 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA

More information

JavaScript Handling Events Page 1

JavaScript Handling Events Page 1 JavaScript Handling Events Page 1 1 2 3 4 5 6 7 8 Handling Events JavaScript JavaScript Events (Page 1) An HTML event is something interesting that happens to an HTML element Can include: Web document

More information

Session 16. JavaScript Part 1. Reading

Session 16. JavaScript Part 1. Reading Session 16 JavaScript Part 1 1 Reading Reading Wikipedia en.wikipedia.org/wiki/javascript / p W3C www.w3.org/tr/rec-html40/interact/scripts.html Web Developers Notes www.webdevelopersnotes.com/tutorials/javascript/

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

5. JavaScript Basics

5. JavaScript Basics CHAPTER 5: JavaScript Basics 88 5. JavaScript Basics 5.1 An Introduction to JavaScript A Programming language for creating active user interface on Web pages JavaScript script is added in an HTML page,

More information

New Media Production Lecture 7 Javascript

New Media Production Lecture 7 Javascript New Media Production Lecture 7 Javascript Javascript Javascript and Java have almost nothing in common. Netscape developed a scripting language called LiveScript. When Sun developed Java, and wanted Netscape

More information

Programming language components

Programming language components Programming language components syntax: grammar rules for defining legal statements what's grammatically legal? how are things built up from smaller things? semantics: what things mean what do they compute?

More information

JavaScript s role on the Web

JavaScript s role on the Web Chris Panayiotou JavaScript s role on the Web JavaScript Programming Language Developed by Netscape for use in Navigator Web Browsers Purpose make web pages (documents) more dynamic and interactive Change

More information

Introduction to JavaScript, Part 2

Introduction to JavaScript, Part 2 Introduction to JavaScript, Part 2 Luka Abrus Technology Specialist, Microsoft Croatia Interaction In the first part of this guide, you learned how to use JavaScript, how to write code and how to see if

More information

JavaScript Functions, Objects and Array

JavaScript Functions, Objects and Array JavaScript Functions, Objects and Array Defining a Function A definition starts with the word function. A name follows that must start with a letter or underscore, followed by any number of letters, digits,

More information

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Java+- Language Reference Manual

Java+- Language Reference Manual Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect

More information

DOM Primer Part 2. Contents

DOM Primer Part 2. Contents DOM Primer Part 2 Contents 1. Event Programming 1.1 Event handlers 1.2 Event types 1.3 Structure modification 2. Forms 2.1 Introduction 2.2 Scripting interface to input elements 2.2.1 Form elements 2.2.2

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

a Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example

a Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example Why JavaScript? 2 JavaScript JavaScript the language Web page manipulation with JavaScript and the DOM 1994 1995: Wanted interactivity on the web Server side interactivity: CGI Common Gateway Interface

More information

By the end of this section of the practical, the students should be able to:

By the end of this section of the practical, the students should be able to: By the end of this section of the practical, the students should be able to: Write JavaScript to generate HTML Create simple scripts which include input and output statements, arithmetic, relational and

More information

What Is JavaScript? A scripting language based on an object-orientated programming philosophy.

What Is JavaScript? A scripting language based on an object-orientated programming philosophy. What Is JavaScript? A scripting language based on an object-orientated programming philosophy. Each object has certain attributes. Some are like adjectives: properties. For example, an object might have

More information

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011 INTRODUCTION TO WEB DEVELOPMENT AND HTML Lecture 15: JavaScript loops, Objects, Events - Spring 2011 Outline Selection Statements (if, if-else, switch) Loops (for, while, do..while) Built-in Objects: Strings

More information

The JavaScript Language

The JavaScript Language The JavaScript Language INTRODUCTION, CORE JAVASCRIPT Laura Farinetti - DAUIN What and why JavaScript? JavaScript is a lightweight, interpreted programming language with object-oriented capabilities primarily

More information

COMS 469: Interactive Media II

COMS 469: Interactive Media II COMS 469: Interactive Media II Agenda Review Ch. 5: JavaScript An Object-Based Language Ch. 6: Programming the Browser Review Data Types & Variables Data Types Numeric String Boolean Variables Declaring

More information

JavaScript: Fundamentals, Concepts, Object Model

JavaScript: Fundamentals, Concepts, Object Model JavaScript: Fundamentals, Concepts, Object Model Prof. Ing. Andrea Omicini Ingegneria Due, Università di Bologna a Cesena andrea.omicini@unibo.it 2006-2007 JavaScript A scripting language: interpreted,

More information

FALL 2017 CS 498RK JAVASCRIPT. Fashionable and Functional!

FALL 2017 CS 498RK JAVASCRIPT. Fashionable and Functional! CS 498RK FALL 2017 JAVASCRIPT Fashionable and Functional! JAVASCRIPT popular scripting language on the Web, supported by browsers separate scripting from structure (HTML) and presentation (CSS) client-

More information

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard Introduction to Prof. Ing. Andrea Omicini II Facoltà di Ingegneria, Cesena Alma Mater Studiorum, Università di Bologna andrea.omicini@unibo.it Documents and computation HTML Language for the description

More information

Midterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can.

Midterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can. First Name Last Name CSCi 90.3 March 23, 2010 Midterm Exam Instructions: For multiple choice questions, circle the letter of the one best choice unless the question explicitly states that it might have

More information

More on JavaScript Functions

More on JavaScript Functions More on JavaScript Functions Nesting Function Definitions Function definitions can be nested. function hypotenuse(a, b) function square(x) return x * x; return Math.sqrt(square(a) + square(b));

More information

CICS 515 a Internet Programming Week 3. Mike Feeley

CICS 515 a Internet Programming Week 3. Mike Feeley CICS 515 a Internet Programming Week 3 Mike Feeley JavaScript JavaScript is not Java client-side scripting language program that runs in browser at client two ways to include it in HTML document embedded

More information

JavaScript: The Basics

JavaScript: The Basics JavaScript: The Basics CISC 282 October 4, 2017 JavaScript A programming language "Lightweight" and versatile Not universally respected Appreciated in the web domain Adds programmatic functionality to

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

CERTIFICATE IN WEB PROGRAMMING

CERTIFICATE IN WEB PROGRAMMING COURSE DURATION: 6 MONTHS CONTENTS : CERTIFICATE IN WEB PROGRAMMING 1. PROGRAMMING IN C and C++ Language 2. HTML/CSS and JavaScript 3. PHP and MySQL 4. Project on Development of Web Application 1. PROGRAMMING

More information

Spring JavaScript. John Mitchell Adapted by Mooly Sagiv. Reading: links on last slide Homework 1: 18/3 17/4

Spring JavaScript. John Mitchell Adapted by Mooly Sagiv. Reading: links on last slide Homework 1: 18/3 17/4 Spring 2012 JavaScript John Mitchell Adapted by Mooly Sagiv Reading: links on last slide Homework 1: 18/3 17/4 Why talk about JavaScript? Very widely used, and growing Web pages, AJAX, Web 2.0 Increasing

More information

Dynamic Web Pages - Integrating JavaScript into a SAS Web Application Caroline Bahler, ASG, Inc.

Dynamic Web Pages - Integrating JavaScript into a SAS Web Application Caroline Bahler, ASG, Inc. Dynamic Web Pages - Integrating JavaScript into a SAS Web Application Caroline Bahler, ASG, Inc. Abstract The use of dynamic web pages in either Internet or Intranet applications is rapidly becoming the

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material. Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc WA2442 Introduction to JavaScript Objectives This intensive training course

More information

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017 MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017 Language Guru: Kimberly Hou - kjh2146 Systems Architect: Rebecca Mahany - rlm2175 Manager: Jordi Orbay - jao2154

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

JavaScript Lecture 1

JavaScript Lecture 1 JavaScript Lecture 1 Waterford Institute of Technology May 17, 2016 John Fitzgerald Waterford Institute of Technology, JavaScriptLecture 1 1/31 Javascript Extent of this course A condensed basic JavaScript

More information

Notes on JavaScript (aka ECMAScript) and the DOM

Notes on JavaScript (aka ECMAScript) and the DOM Notes on JavaScript (aka ECMAScript) and the DOM JavaScript highlights: Syntax and control structures superficially resemble Java/C/C++ Dynamically typed Has primitive types and strings (which behave more

More information

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Name Related Elements Type Default Depr. DTD Comment

Name Related Elements Type Default Depr. DTD Comment Legend: Deprecated, Loose DTD, Frameset DTD Name Related Elements Type Default Depr. DTD Comment abbr TD, TH %Text; accept-charset FORM %Charsets; accept FORM, INPUT %ContentTypes; abbreviation for header

More information

Javascript Arrays, Object & Functions

Javascript Arrays, Object & Functions Javascript Arrays, Object & Functions Agenda Creating & Using Arrays Creating & Using Objects Creating & Using Functions 2 Creating & Using Arrays Arrays are a type of object that are ordered by the index

More information