JavaScript I VP R 1. Copyright 2006 Haim Levkowitz. Outline

Size: px
Start display at page:

Download "JavaScript I VP R 1. Copyright 2006 Haim Levkowitz. Outline"

Transcription

1 JavaScript I VP R 1 Outline Goals and Objectives Introduction JavaScript and Java Embedding JavaScript in XHTML Variables Statements Expressions and Operators Control Structures Code Execution Input and Output I VP R 2 1

2 Goals Understand JavaScript Basics Syntax code execution order debugging and testing inclusion in XHTML and Web pages reasons for using JavaScript in Web pages I VP R 3 Objectives Why use JavaScript? Why not? JavaScript Syntax Embedding JavaScript in XHTML Variables Statements Operators Control Structures Input/Output I VP R 4 2

3 Introduction XHTML limited dynamics JavaScript used in web pages for: Dynamics mouse clicks pop up windows animations Client-side execution validating input processing requests I VP R 5 Executed on client-side Avoids Client/Server communication and traffic Simple, interpretive Requires only web browser But I VP R 6 3

4 But Lots of security problems, vulnerabilities JavaScript bugs Browser bugs Foreign code If possible, better without than with (IMHO) I VP R 7 History Originally: Netscape, as LiveScript 1995: joint venture of Netscape and Sun renamed JavaScript Now standardized by European Computer Manufacturers Association ECMA-262 also ISO We call collections of JavaScript code scripts not programs I VP R 8 4

5 JavaScript and Java only related through syntax JavaScript dynamically typed support for objects very different I VP R 9 JavaScript and Java Java JavaScript Class-based object model Prototype-based model Special declarations No special declarations Explicit variable types Implicit variable types JavaScript very free form language Compared to Java offers tools to much wider, less-sophisticated audience I VP R 10 5

6 JavaScript can be used to replace some of what typically done with Applets except graphics CGI no file operations or networking I VP R 11 User interactions through forms easy Document Object Model (DOM) possible to support dynamic HTML documents with JavaScript Event-Driven Computation User interactions with HTML documents in JavaScript use event-driven model of computation User interactions with form elements can be used to trigger execution of scripts I VP R 12 6

7 Object Orientation and JavaScript NOT object-oriented programming language Does not support class-based inheritance Cannot support polymorphism Has prototype-based inheritance much different I VP R 13 JavaScript Objects collections of properties like members of classes in Java and C++ has primitives for simple types root object is Object objects derived from Object All JavaScript objects accessed through references I VP R 14 7

8 Embedding JavaScript in HTML <script> tag used to embed JavaScript code in HTML code can be used anywhere inside code usually embedded right before or after <head> tag closes Nesting prohibited generates errors I VP R 15 Directly <script type = text/javascript"> -- JavaScript script </script> I VP R 16 8

9 Indirectly as file specified in src attribute of <script> <script type = text/javascript src = "myscript.js"> </script> I VP R 17 Syntax Identifier form begin with letter or underscore followed by any number of letters, underscores, digits Case sensitive 25 reserved words plus future reserved words Comments: both // and /* */ I VP R 18 9

10 Reserve words I VP R 19 hide scripts from browsers wo JavaScript interpreters put in special comments <!-- -- JavaScript script //--> Semicolons can be problem somewhat optional Problem: When end of line can be end of statement JavaScript puts semicolon I VP R 20 10

11 JavaScript is dynamically typed any variable can be used for anything primitive value reference to any object interpreter determines type of particular occurrence of variable I VP R 21 Variables can be declared Implicitly explicitly var sum = 0, today = "Monday", flag = false; I VP R 22 11

12 Variables Data types Implicit converted automatically first use of variable declares its type Types can be numbers (integer or real) logical (Boolean) String Examples: 3, 40, -10.5, true, false, string, 9abc I VP R 23 Scope Code block where variable available Global variable available everywhere easy to manage bad habit Local variable available only inside block where specified I VP R 24 12

13 Constants const keyword Read-only variable Cannot change values be re declared Example: const x=35 I VP R 25 Literals Fixed values (not variables) hard-coded Nesting needs extra care Change quotes from to If not confusion Examples: 3.5, false, Hello I VP R 26 13

14 Data Type Conversion Automatic Possible confusion Examples: answer=true, answer=35 I VP R 27 Escaping and Special Characters \ : escaping character define special character sequences I VP R 28 14

15 Primitives, Operations, & Expressions All primitive values have one of five primitive types Number, String, Boolean have wrapper objects Number, String, Boolean Undefined, Null I VP R 29 In cases of Number and String primitive values and objects coerced back and forth primitive values can be treated essentially as if they were objects I VP R 30 15

16 Numeric literals just like Java All numeric values stored in doubleprecision floating point String literals delimited by either ' or " Can include escape sequences (e.g., \t) All String literals are primitive values I VP R 31 Boolean values true and false only Null value is null only Undefined value is undefined I VP R 32 16

17 Numeric operators ++, --, +, -, *, /, % All operations in double precision Same precedence and associativity as Java I VP R 33 Math Object provides floor, round, max, min, trig functions, etc. e.g., Math.cos(x) Number Object MAX_VALUE, MIN_VALUE, NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY, PI e.g., Number.MAX_VALUE arithmetic operation that creates overflow returns NaN NaN is not == to any number not even itself Test for it with isnan(x) Number object has method, tostring I VP R 34 17

18 I VP R 35 The typeof operator Returns "number", "string", or "boolean" for primitives returns "object" for objects and null I VP R 36 18

19 Assignment statements Like C++ and Java I VP R 37 The Date Object Create one with Date constructor (no params) Local time methods of Date : tolocalestring returns string of date getdate returns day of month getmonth returns month of year (0 11) getday returns day of week (0 6) getfullyear returns year gettime returns number of msec s since January 1, 1970 gethours returns hour (0 23) getminutes returns minutes (0 59) getmilliseconds returns millisecond (0 999) I VP R 38 19

20 Screen Output & Keyboard Input JavaScript model for HTML document Document object browser display window Window object two properties document: refer to Document object window: refer to Window object I VP R 39 Methods Document object has method write dynamically creates content parameter is string often concatenated from parts Some are variables, e.g., document.write("answer: " + result + "<br />"); parameter sent to browser can be anything that can appear in HTML doc <br /> but not \n I VP R 40 20

21 Window object has three methods for creating dialog boxes alert confirm prompt I VP R 41 alert alert( The sum is: 42 \n"); Parameter is plain text, not HTML Opens dialog box displays parameter string OK button waits for user to press OK button I VP R 42 21

22 confirm confirm("do you want to continue this download?"); Opens dialog box displays Parameter two buttons OK Cancel waits for button press Returns Boolean value depending on button pressed I VP R 43 prompt prompt("what is your name?", ""); Opens dialog box displays string parameter text box Two buttons OK Cancel waits for OK second parameter for default response if user presses OK without typing response in text box I VP R 44 22

23 roots.html I VP R 45 Control Statements Similar to C, C++, Java Compound statements delimited by braces But are not blocks I VP R 46 23

24 Control expressions three kinds Primitive values Relational Expressions Compound Expressions I VP R 47 Primitive values String true unless empty or "0" Number true unless zero I VP R 48 24

25 Relational Expressions The usual six: ==,!=, <, >, <=, >= Operands coerced if necessary If one is string and one is number attempts to convert string to number If one is Boolean and other not Boolean operand coerced to number (1 or 0) I VP R 49 The unusual two: ===,!== Same as ==,!= but no coercions operands must be identical Comparisons of references to objects not useful addresses compared, not values I VP R 50 25

26 Relational Expressions I VP R 51 Operator Precedence and Associativity I VP R 52 26

27 Compound Expressions The usual operators: &&,,! Boolean object has method tostring can be printed (true or false) I VP R 53 Selection Statements The usual if-then-else clauses can be either single statements compound statements I VP R 54 27

28 Switch statements can be either Statement sequences compound statements control expression can be Number String Boolean Different cases can have values of different types I VP R 55 switch (expression) { case value_1: // value_1 statements case value_2: // value_2 statements [default: // default statements] } I VP R 56 28

29 borders2.html I VP R 57 Loop statements while (control_expression) statement or cmpnd for (init; control; increment) statement or cmpnd init can have declarations, but scope of such variables is whole script do statement or compound while (control_expression) Example I VP R 58 29

30 Example: date.html I VP R 59 Object Creation and Modification Objects can be created with new most basic object one that uses Object constructor as in var myobject = new Object(); new object has no properties blank object Properties can be added to object any time I VP R 60 30

31 var myairplane = new Object(); myairplane.make = "Cessna"; myairplane.model = "Centurian"; I VP R 61 Objects can be nested property could be another object created with new Properties can be accessed by dot notation, or in array notation, as in var property1 = myairplane["model"]; delete myairplane.model; I VP R 62 31

32 Another Loop Statement for (identifier in object) statement or compound for (var prop in myairplane) document.write(myairplane[prop] + "<br />"); I VP R 63 Arrays Objects with some special functionality Array elements can be primitive values references to other objects Length is dynamic length property stores length I VP R 64 32

33 Array objects can be created in two ways with new, or by assigning array literal I VP R 65 var mylist = new Array(24, "bread", true); var mylist2 = [24, "bread", true]; var mylist3 = new Array(24); I VP R 66 33

34 length of array - highest subscript to which element has been assigned + 1 mylist[122] = "bitsy"; // length is 123 I VP R 67 length property is writeable ==> can set to make array any desirable length E.g., mylist.length = 150; I VP R 68 34

35 insert_names.html I VP R 69 Array methods join e.g., var liststr = list.join(", "); I VP R 70 35

36 Array methods, cont. - reverse - sort - e.g., -names.sort(); - Coerces elements to strings - puts them in alphabetical order - concat e.g., newlist = list.concat(47, 26); I VP R 71 Array methods, cont. slice listpart = list.slice(2, 5); listpart2 = list.slice(2); I VP R 72 36

37 Array methods, cont. tostring Coerce elements to strings if necessary concatenate them together separated by commas exactly like join(", ") I VP R 73 Array methods, cont. - push, pop, unshift, and shift I VP R 74 37

38 nested_arrays.html I VP R 75 Functions function function_name([formal_parameters]) { -- body } I VP R 76 38

39 Functions (continued) Return value is parameter of return If there is no return or if end of function reached ==> undefined returned If return has no parameter ==> undefined returned I VP R 77 Functions (continued) Functions are objects ==> variables that reference them can be treated as other object references I VP R 78 39

40 Functions (continued) If fun is the name of a function ref_fun = fun;... ref_fun(); /* A call to fun */ I VP R 79 Functions (continued) place all function definitions in head of HTML document All variables that are declared outside functions either implicitly or explicitly ==> are global Variables explicitly declared in a function ==> are local I VP R 80 40

41 Functions (continued) Parameters passed by value, but when reference variable passed ==> semantics are pass-by-reference I VP R 81 Functions (continued) No checking of parameters type number excess parameters actual ignored formal set to undefined I VP R 82 41

42 Functions (continued) All parameters sent through property array Arguments has length property I VP R 83 Functions (continued) parameters.html and output I VP R 84 42

43 Functions (continued) no clean way to send primitive by reference One dirty way put value in array and send array s name I VP R 85 function by10(a) { a[0] *= 10; }... var listx = new Array(1);... listx[0] = x; by10(listx); x = listx[0]; I VP R 86 43

44 Functions (continued) To sort something other than strings into alphabetical order write function that performs comparison send it to sort method comparison function must return Negative number, zero, or positive number indicate whether order ok, equal, or not I VP R 87 function num_order(a, b) {return a - b;} Now, can sort array named num_list with: num_list.sort(num_order); I VP R 88 44

45 Example medians.html & output I VP R 89 Constructors Used to initialize objects actually create the properties I VP R 90 45

46 function plane(newmake, newmodel, newyear){ this.make = newmake; this.model = newmodel; this.year = newyear; } myplane = new plane("cessna", "Centurnian", "1970"); I VP R 91 I VP R 92 46

47 Can also have method properties function displayplane() { document.write("make: ", this.make, "<br />"); document.write("model: ", this.model, "<br />"); document.write("year: ", this.year, "<br />"); } I VP R 93 Now add this to the constructor: this.display = displayplane; I VP R 94 47

48 Pattern matching two ways 1. Use RegExp objects 2. Use methods on String objects I VP R 95 Simple patterns Two categories of characters in patterns: a. normal characters match themselves b. metacharacters can have special meanings in patterns do not match themselves I VP R 96 48

49 metacharacter \ ( ) [ ] { } ^ $ * +?. metacharacter treated as normal character if backslashed = escaped period = special metacharacter matches any character except newline I VP R 97 search(pattern) Returns position in object string of pattern relative to zero -1 if fails var str = "Gluckenheimer"; var position = str.search(/n/); /* position is now 6 */ I VP R 98 49

50 Character classes sequence of characters in brackets ==> defines set of characters any one of which matches [abcd] Dashes to specify spans of characters in class [a-z] Caret at left end of class definition means opposite [^0-9] I VP R 99 I VP R

51 Character class abbreviations Abbr. Equiv. Pattern Matches \d [0-9] a digit \D [^0-9] not a digit \w [A-Za-z_0-9] a word character \W [^A-Za-z_0-9] not a word character \s [ \r\t\n\f] a whitespace character \S [^ \r\t\n\f] not a whitespace character Variables in patterns are interpolated I VP R 101 Quantifiers Quantifiers in braces Quantifier {n} {m,} {m, n} Meaning exactly n repetitions at least m repetitions at least m but not more than n repetitions I VP R

52 Other quantifiers abbreviations for most commonly used quantifiers * = zero or more repetitions e.g., \d* ==> zero or more digits + = one or more repetitions e.g., \d+ ==> one or more digits? = zero or one e.g., \d? ==> zero or one digit I VP R 103 Anchors pattern can be forced to match only at left end: with ^ End: with $ e.g., /^Lee/ matches "Lee Ann" but not "Mary Lee Ann" /Lee Ann$/ matches "Mary Lee Ann but not "Mary Lee Ann is nice" I VP R

53 anchor operators (^ and $) do not match characters in string match positions at beginning or end I VP R 105 Pattern modifiers The i modifier tells matcher to ignore case of letters /oak/i matches "OAK" and "Oak" and The x modifier tells matcher to ignore whitespace in pattern allows comments in patterns I VP R

54 Other Pattern Matching Methods of String replace(pattern, string) Finds substring that matches pattern replaces it with string g modifier can be used var str = "Some rabbits are rabid"; str.replace(/rab/g, "tim"); str is now "Some timbits are timid" $1 and $2 both set to "rab" I VP R 107 match(pattern) most general pattern-matching method Returns array of results of pattern-matching operation With g modifier returns array of substrings that matched Without g modifier first element of returned array has matched substring other elements have values of $1, I VP R

55 var str = "My 3 kings beat your 2 aces"; var matches = str.match(/[ab]/g); matches is set to ["b", "a", "a"] I VP R 109 split(parameter) "," and /,/ both work I VP R

56 forms_check.html I VP R 111 Debugging IE6 Mozilla I VP R

57 IE6 Select Internet Options from the Tools menu Choose Advanced tab Uncheck Disable script debugging box Check Display a notification about every script error box Now, script error ==> small window opened with explanation of error I VP R 113 Mozilla / Firefox / Netscape 7 Select Tasks, Tools, and JavaScript Console small window appears to display script errors Remember to Clear console after using error message avoids confusion Select Tools, Web Development, JavaScript Console I VP R

58 Summary JavaScript : make web page dynamic JavaScript and Java fundamentally different JavaScript code embedded in X/HTML code written and tested like X/HTML code I VP R 115 variables statements to build code block operators control structures to control code execution Arrays Functions Pattern matching Input / output I VP R

4.1 Overview of JavaScript

4.1 Overview of JavaScript 4.1 Overview of JavaScript - Originally developed by Netscape by Brendan Eich, as LiveScript - Became a joint venture of Netscape and Sun in 1995, renamed JavaScript - Now standardized by the European

More information

Lecture 6 Part a: JavaScript

Lecture 6 Part a: JavaScript Lecture 6 Part a: JavaScript G64HLL, High Level Languages http://www.cs.nott.ac.uk/~gxo/g64hll.html Dr. Gabriela Ochoa gxo@cs.nott.ac.uk Previous lecture Basics of java script The document, window objects

More information

Chapter 4 Basics of JavaScript

Chapter 4 Basics of JavaScript Chapter 4 Basics of JavaScript JavaScript/EcmaScript References The official EcmaScript, third edition, specification http://www.ecma-international.org/publications/files/ecma-st/ecma-262.pdf A working

More information

CS1520 Recitation Week 2

CS1520 Recitation Week 2 CS1520 Recitation Week 2 Javascript http://cs.pitt.edu/~jlee/teaching/cs1520 Jeongmin Lee, (jlee@cs.pitt.edu) Today - Review of Syntax - Embed code - Syntax - Declare variable - Numeric, String, Datetime

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

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

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 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

ID1354 Internet Applications

ID1354 Internet Applications ID1354 Internet Applications JavaScript Leif Lindbäck, Nima Dokoohaki leifl@kth.se, nimad@kth.se SCS/ICT/KTH Overview of JavaScript Originally developed by Netscape, as LiveScript Became a joint venture

More information

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17 PIC 40A Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers 04/24/17 Copyright 2011 Jukka Virtanen UCLA 1 Objects in JS In C++ we have classes, in JS we have OBJECTS.

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

UNIT-4 JAVASCRIPT. Prequisite HTML/XHTML. Origins

UNIT-4 JAVASCRIPT. Prequisite HTML/XHTML. Origins UNIT-4 JAVASCRIPT Overview of JavaScript JavaScript is a sequence of statements to be executed by the browser. It is most popular scripting language on the internet, and works in all major browsers, such

More information

Javascript Methods. concat Method (Array) concat Method (String) charat Method (String)

Javascript Methods. concat Method (Array) concat Method (String) charat Method (String) charat Method (String) The charat method returns a character value equal to the character at the specified index. The first character in a string is at index 0, the second is at index 1, and so forth.

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

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

3 The Building Blocks: Data Types, Literals, and Variables

3 The Building Blocks: Data Types, Literals, and Variables chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating

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

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1 Objectives INFS 2150 Introduction to Web Development and e-commerce Technology Programming with JavaScript JavaScript client-side programming Example of a JavaScript program The element

More information

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript INFS 2150 Introduction to Web Development and e-commerce Technology Programming with JavaScript 1 Objectives JavaScript client-side programming Example of a JavaScript program The element

More information

UNIT-III THE BASICS OF JAVASCRIPT

UNIT-III THE BASICS OF JAVASCRIPT UNIT-III THE BASICS OF JAVASCRIPT 3.1 Overview of Javascript 3.1.1 Origins Javascript which was originally developed at Netscape by Brendan Eich, was initially named Mocha but soon after was renamed LiveScript.

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

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

JavaScript: More Syntax and Using Events

JavaScript: More Syntax and Using Events JavaScript: Me Syntax and Using Events CISC 282 October 4, 2017 null and undefined null is synonymous with nothing i.e., no value, nothing there undefined in synonymous with confusion i.e., what's this?

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

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

\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

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 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

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

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

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore 560 100 WEB PROGRAMMING Solution Set II Section A 1. This function evaluates a string as javascript statement or expression

More information

15.1 Origins and Uses of Ruby

15.1 Origins and Uses of Ruby 15.1 Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in 1996 - Use spread rapidly in Japan - Use is now growing in part because of its use in Rails - A pure object-oriented purely interpreted

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

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

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

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating

More information

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating

More information

Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl)

Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) Regular Expressions Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) JavaScript started supporting regular expressions in

More information

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

Chapter 17. Fundamental Concepts Expressed in JavaScript

Chapter 17. Fundamental Concepts Expressed in JavaScript Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program

More information

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP Chapter 11 Introduction to PHP 11.1 Origin and Uses of PHP Developed by Rasmus Lerdorf in 1994 PHP is a server-side scripting language, embedded in XHTML pages PHP has good support for form processing

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

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

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

Variables and Typing

Variables and Typing Variables and Typing Christopher M. Harden Contents 1 The basic workflow 2 2 Variables 3 2.1 Declaring a variable........................ 3 2.2 Assigning to a variable...................... 4 2.3 Other

More information

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

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

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

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective- UNIT -II Style Sheets: CSS-Introduction to Cascading Style Sheets-Features- Core Syntax-Style Sheets and HTML Style Rle Cascading and Inheritance-Text Properties-Box Model Normal Flow Box Layout- Beyond

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT Python The way of a program Srinidhi H Asst Professor Dept of CSE, MSRIT 1 Problem Solving Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution

More information

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010 IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Lecture 12. PHP. cp476 PHP

Lecture 12. PHP. cp476 PHP Lecture 12. PHP 1. Origins of PHP 2. Overview of PHP 3. General Syntactic Characteristics 4. Primitives, Operations, and Expressions 5. Control Statements 6. Arrays 7. User-Defined Functions 8. Objects

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Chapter 3 Data Types and Variables

Chapter 3 Data Types and Variables Chapter 3 Data Types and Variables Adapted from JavaScript: The Complete Reference 2 nd Edition by Thomas Powell & Fritz Schneider 2004 Thomas Powell, Fritz Schneider, McGraw-Hill Jargon Review Variable

More information

Section 2: Introduction to Java. Historical note

Section 2: Introduction to Java. Historical note The only way to learn a new programming language is by writing programs in it. - B. Kernighan & D. Ritchie Section 2: Introduction to Java Objectives: Data Types Characters and Strings Operators and Precedence

More information

Chapter 2 Working with Data Types and Operators

Chapter 2 Working with Data Types and Operators JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010 Lecture 14 Javascript Announcements Project #2 New website Exam#2 No. Class Date Subject and Handout(s) 17 11/4/10 Examination Review Practice Exam PDF 18 11/9/10 Search, Safety, Security Slides PDF UMass

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

Lesson 1: Writing Your First JavaScript

Lesson 1: Writing Your First JavaScript JavaScript 101 1-1 Lesson 1: Writing Your First JavaScript OBJECTIVES: In this lesson you will be taught how to Use the tag Insert JavaScript code in a Web page Hide your JavaScript

More information

University Convocation IT 3203 Introduction to Web Development Creating Objects Accessing Property Values

University Convocation IT 3203 Introduction to Web Development Creating Objects Accessing Property Values IT 3203 Introduction to Web Development JavaScript II Labeling Systems October 7 Notice: This session is being recorded. Copyright 2007 by Bob Brown University Convocation Tuesday, October 13, 11:00 12:15

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

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

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

Language Reference Manual

Language Reference Manual TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts

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

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

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

Programming with C++ as a Second Language

Programming with C++ as a Second Language Programming with C++ as a Second Language Week 2 Overview of C++ CSE/ICS 45C Patricia Lee, PhD Chapter 1 C++ Basics Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Introduction to

More information

JavaScript: Introductionto Scripting

JavaScript: Introductionto Scripting 6 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask, What would be the most fun? Peggy Walker Equality,

More information

PHP. Interactive Web Systems

PHP. Interactive Web Systems PHP Interactive Web Systems PHP PHP is an open-source server side scripting language. PHP stands for PHP: Hypertext Preprocessor One of the most popular server side languages Second most popular on GitHub

More information

9.1 Origins and Uses of Perl

9.1 Origins and Uses of Perl 9.1 Origins and Uses of Perl - Began in the late 1980s as a more powerful replacement for the capabilities of awk (text file processing) and sh (UNIX system administration) - Now includes sockets for communications

More information

COMP6700/2140 Data and Types

COMP6700/2140 Data and Types COMP6700/2140 Data and Types Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU February 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

JavaScript Basics. The Big Picture

JavaScript Basics. The Big Picture JavaScript Basics At this point, you should have reached a certain comfort level with typing and running JavaScript code assuming, of course, that someone has already written it for you This handout aims

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

JME Language Reference Manual

JME Language Reference Manual JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

Typescript on LLVM Language Reference Manual

Typescript on LLVM Language Reference Manual Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

HTML5 and CSS3 More JavaScript Page 1

HTML5 and CSS3 More JavaScript Page 1 HTML5 and CSS3 More JavaScript Page 1 1 HTML5 and CSS3 MORE JAVASCRIPT 3 4 6 7 9 The Math Object The Math object lets the programmer perform built-in mathematical tasks Includes several mathematical methods

More information

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof. GridLang: Grid Based Game Development Language Language Reference Manual Programming Language and Translators - Spring 2017 Prof. Stephen Edwards Akshay Nagpal Dhruv Shekhawat Parth Panchmatia Sagar Damani

More information

Pathologically Eclectic Rubbish Lister

Pathologically Eclectic Rubbish Lister Pathologically Eclectic Rubbish Lister 1 Perl Design Philosophy Author: Reuben Francis Cornel perl is an acronym for Practical Extraction and Report Language. But I guess the title is a rough translation

More information

The Warhol Language Reference Manual

The Warhol Language Reference Manual The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

More information

JavaScript by Vetri. Creating a Programmable Web Page

JavaScript by Vetri. Creating a Programmable Web Page XP JavaScript by Vetri Creating a Programmable Web Page 1 XP Tutorial Objectives o Understand basic JavaScript syntax o Create an embedded and external script o Work with variables and data o Work with

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

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Types and Expressions. Chapter 3

Types and Expressions. Chapter 3 Types and Expressions Chapter 3 Chapter Contents 3.1 Introductory Example: Einstein's Equation 3.2 Primitive Types and Reference Types 3.3 Numeric Types and Expressions 3.4 Assignment Expressions 3.5 Java's

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: Introduction, Types

JavaScript: Introduction, Types JavaScript: Introduction, Types Computer Science and Engineering College of Engineering The Ohio State University Lecture 19 History Developed by Netscape "LiveScript", then renamed "JavaScript" Nothing

More information