JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.

Slides:



Advertisements
Similar presentations
/ 251 Internet Applications Ahmed M. Zeki Sem – / Chapter 8.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
1 HCI 201 JavaScript - Part 1. 2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Information Technology Center Hany Abdelwahab Computer Specialist.
JavaScript, Fourth Edition
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Introduction to scripting
CST JavaScript Validating Form Data with JavaScript.
4.1 JavaScript Introduction
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Using Client-Side Scripts to Enhance Web Applications 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
JavaScript and Ajax (JavaScript Data Types) Week 2 Web site:
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
Definition of the Programming Language CPRL
>> Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
Web Database Programming Using PHP
Scope, Objects, Strings, Numbers
Introduction to Scripting
JavaScript Syntax and Semantics
JavaScript.
JavaScript an introduction.
WEB PROGRAMMING JavaScript.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript What is JavaScript? What can JavaScript do?
Web DB Programming: PHP
JavaScript What is JavaScript? What can JavaScript do?
Tutorial 10: Programming with javascript
PHP an introduction.
CIS 136 Building Mobile Apps
Presentation transcript:

JavaScript I

JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some syntactic resemblance. Enables control of the content of web pages, browsers and HTML forms. It is a case-sensitive language. Uses of JavaScript Client side validation of form data, prior to submission Performing arbitrary computations Controlling document appearance and content In combination with CSS, for creating DHTML (Dynamic HTML).

Enabling user interactivity by displaying messages or alert boxes in response to user input. Read and write client state with cookies Producing animation effects with images Interaction with Java applets Comments in JavaScript // for single line comments /*….*/ for multiple line comments Literals A literal is a data value that appears directly in a program e.g. a string of text or a numeric value.

Identifiers An identifier is simply a name. Used to name variables and functions in JavaScript. Rules for identifiers are similar to those in Java and other programming languages The first character must be a letter, an underscore _, or $ Subsequent characters can be a letter or digit. Reserved words These are words that can not be used as identifiers, as they are part of the language syntax. Include words such as break, case, catch, continue, default, delete, do, else, false, finally, for, function, if, in, new, null, return, switch, this, throw, true, try, var, void and while.

Data Types The types of values that can be represented and manipulated by a programming language JavaScript supports: Numbers Strings (strings of text) Boolean values Object: An object is a composite data type that represents a collection of values such as numbers and strings, or other objects. Numbers Most basic data type. Represented in JavaScript as floating-point values Can represent numbers as large as * and as small as 5*

Strings A sequence of Unicode letters, digits and punctuation marks enclosed in matching pairs of single or double quotation marks. Double-quote character should be enclosed in single quotation marks Single-quote enclosed in double quotation marks Escape sequences in string literals \n creates a new line \ represents the single quote or apostrophe e.g You\re not would translate to Youre not \\ represents backslash, and \r represents carriage return.

Working with Strings Concatenation: JavaScript has a built-in feature that allows joining one string to another with the + operator e.g We have + moved on to JavaScript; results in We have moved on to JavaScript Length: Determines the numbers of characters contained in a string. E.g. to determine the number of characters in a variable called s, the syntax is s.length To get the last character in a string: last_char = s.charAt(s.length – 1); To find the position of the first letter a in a string s, position_of_a = s.indexOf(a);

Boolean Values Has only 2 possible values (True or False) Generally the result of comparisons made within a script. Typically used in control structures e.g if/else statements perform one action if a boolean value is true and another action if the value is false. Functions Piece of executable code that is defined by a JavaScript program, or predefined by the JavaScript implementation. Defined only once, but can be executed or invoked any number of times. May be passed arguments or parameters that specify value(s) upon which it is to perform its computation.

Functions (contd.) May return value that represents the results of computation. JavaScript implementations provide many predefined functions, such as Math.sin() function that computes the sine of an angle. Example: function square(x) // the function is named square and expects { // one argument, x. The body is enclosed in return x*x; // curly brackets. This function squares its } // argument and returns the value. Invoking Functions b = square(x); y = Math.sin(x)

Objects Collection of named values The named values are usually referred to as properties of the object. The properties are usually represented as the name of the object followed by a period (.), followed by the name of the property e.g. if an object named image has properties named width and height, theyll be represented as image.width and image.height, respectively. Creating Objects Objects are created by invoking special constructor functions. var o = new Object(); Once created, you can use and set its properties e.g. var point = new Object(); point.x = 2.3; point.y = 4.5;

Object Literals Also called object initializer. The point object can be created and initialized with the following code: var point = {x:2, y:4}; Object literals can also be nested. E.g. var rectangle = { upperLeft: { x:2, y:4 }, lowerRight: { x:6, y:10 } }; The property values used in object literals do not have to be constants, i.e. they could be expressions e.g. var rectangle = { upperLeft: { x:point.x, y:point.y }, lowerRight: { x:(point.x + ln), y:(point.y + ln2)} };

Arrays Collection of data values, similar to an object. While each data value in an object has a name, each data value in an array has an index. The index is a positive integer. Arrays may contain any type of JavaScript data, including references to other arrays or objects Example: If an array is named a, and n is a positive integer, a[n] is an element of the array. Array indexes begin with zero, therefore a[2] is the third element of the array a. References: Dietel, Dietel & Nieto Chapter 8 JavaScript The Definitive guide 4 th Ed. David Flanagan. Chapters 1, 2 & 3