JavaScript JavaScript is a scripting language that is most commonly used to add client- side programming to a web page. Some of the things it is used for.

Slides:



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

Introducing JavaScript
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
12-Jun-15 JavaScript Language Fundamentals I. 2 About JavaScript JavaScript is not Java, or even related to Java The original name for JavaScript was.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
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.
Tutorial 10 Programming with JavaScript
Information Technology Center Hany Abdelwahab Computer Specialist.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Week 9 PHP Cookies and Session Introduction to JavaScript.
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.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Chapter 3: Data Types and Operators JavaScript - Introductory.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
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.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
JavaScript, Fourth Edition
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
1 JavaScript in Context. Server-Side Programming.
“The world’s most misunderstood language has become the world’s most popular programming language” Akshay Arora
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
Java Script. introduction Today’s web sites need to go much beyond HTML. browsing through a web site, to actually interact with the web site. The web.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
OVERVIEW OF CLIENT-SIDE SCRIPTING
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
Build in Objects In JavaScript, almost "everything" is an object.
>> Introduction to JavaScript
JavaScript an introduction.
PHP.
JavaScript What is JavaScript? What can JavaScript do?
JavaScript What is JavaScript? What can JavaScript do?
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

JavaScript JavaScript is a scripting language that is most commonly used to add client- side programming to a web page. Some of the things it is used for in web development: Manipulate the HTML elements and CSS Interact with the user Send data back to a server asynchronously (AJAX) Input validation (ex: make a textbox red if it has too many/few characters in it)

Java vs. JavaScript JavaScript has next to nothing to do with Java JavaScript was developed at Netscape in the 90's and was originally called LiveScript. It is believed that the name change to JavaScript was a marketing ploy to take advantage of the popularity of Java. JavaScript syntax is much like C, and therefore much like Java.

JavaScript Details JavaScript is managed by the Mozilla Foundation Client-side: the browser (the client) is able to read & execute the code. *JavaScript can be used server-side for other purposes Interpreted or may be compiled using just-in-time compilation in modern browsers. ECMAScript: The version of JavaScript that was standardized by Ecma International Imperative: Code is written as a sequence of steps to perform Structural: Makes use of decisions (if / else if / else), iteration (for, while), and subroutines and functions

JavaScript Type System Loosely Typed: Variables are not given a type, just “var” Dynamically Typed: The type of the variable is determined at runtime based on its value. The good: You don't have to cast anything, you can switch between types if it suits your code. Example: User types in “10”, you can leave it as is and still compare it to the integer 10. The bad: Type errors will not be detected until runtime, and depending on your exact code they may be easy to miss. Coercion: Implicit type conversion: “2” * “10” --> 20 Conversion: JavaScript provides functions to convert values to other types when necessary

JavaScript Variables & Simple Types Variables var x = 123; var y; //to be used later JavaScript does have types, they are just determined dynamically. Number / Float - Generic number 1.0 is the same as is the same as 1e2 Negative numbers have a – symbol Infinity is a keyword that represents very large numbers Strings can be enclosed in single or double quotes 'Hello' is the same as “Hello” \ is the escape character Boolean – true or false

JavaScript Null, NaN, Undefined NaN (Not a Number) results when an arithmetic operation is invalid. Use the isNaN() function to detect it (==, === won't work because NaN is never equal to itself). A variable is undefined if it was never given a value. Use === for comparisons. null is what you would expect – a null value. You can assign a variable the value of null and compare null to values. Use === for comparisons.

JavaScript Decision Statements If Statements if (condition) { } else if (condition) { } else { } Ternary var answer = x == “Y” ? “Yes” : “No”; Switch Statements switch (expression) { case expression:... break; case expression:... break; default:... }

JavaScript Loops While while (condition) {... } Do While (Will always be executed at least once because the condition is evaluated last) do {... } while (condition) For for (var i = 0; i < 10; i++) {... } for (someProp in someObj) {... }

JavaScript Try & Throw Try / Catch try { } catch (err) { } Throw (Throw a string, number, boolean, object) throw “Some message”;

JavaScript Operators && boolean AND || boolean OR * multiply / divide % modulo + addition or string concatenation - subtraction >=, > greater than or equal, greater than <=, < less than or equal, less than

JavaScript Equality = is for assignment var x = 10; == is for equality (x == 10) //true (x == “10”) //true (x != 9) //true === is for equality including data type (x === 10) // true (x === “10”) // false (x !== “10”) // true

JavaScript Arrays Syntax: var x = [10, 15, “apple”]; var first = x[0];

JavaScript Objects Objects: Heavily used; Objects are associative arrays where the property name is the key. Both dot notation and array notation are supported fruit.color = “red”; fruit[“color”] = “red”; Prototypes: You don't create classes like you do in OOP languages. Instead you create a prototype. Inheritance can be done using a prototype. Feel free to read up on JavaScript prototypes and prototypal inheritance Object Literal Simple notation for creating objects var fruit = {“color”: “red”, “type”: “apple”, “weight”: 0.5};

JavaScript Objects Objects can contain simple values, other objects, arrays, functions var student = { “firstName”: “John”, “lastName”: “Smith”, “uid”: “123456”, “schedule”: [ { “class”: “CS108”, “days”: “MW”, “startTime”:”10:00” }, { “class”: “CS108”, “days”: “MW”, “startTime”:”10:00” } ] }; var firstCourseNum = student.schedule[0].class;

JavaScript Functions JavaScript is a functional language: Functions are first-class. Functions are objects themselves. They can be passed as arguments to other functions, they can be returned from other functions, and a function can be assigned to a variable. Variadic Functions: Functions take a variable number of arguments function someFunc(x, y, z) { document.write(x); document.write(y); document.write(z); document.write(arguments[3]); } someFunc(1, “a”); //z will be undefined someFunc(1, “a”, 2, “b”); //”b” will only be accessible through the special arguments array

Closures * Examples from WikipediaWikipedia A closure is a data structure that stores a function along with an environment. In the example below, the variable in red will be available to the returned function (green) even though it would normally be out of scope.

Anonymous Functions (Lambda) * Examples from WikipediaWikipedia Anonymous functions are unnamed functions, often returned or passed into another function. You do not ever have to use an anonymous function, but sometimes they are convenient.

DOM (Document Object Model) The Document Object Model is a programming interface. The objects in HTML (or XML or XHTML) are represented as nodes in a tree structure, called the DOM tree. These nodes can have event handlers attached to them. The event handlers can call code or functions in languages like JavaScript. Example: Buttons have an onclick event. When a button is clicked, you might want to pop up something asking the user if they are sure they want to perform an action, you might make something on the page change, etc. It is common to hear that you are traversing the DOM looking for an element with JavaScript, or that you are manipulating the DOM with JavaScript. The DOM is standardized. Browsers are supposed to adhere to this standardization.

DOM (Document Object Model) Please read: US/docs/Web/API/Document_Object_Model/Introductionhttps://developer.mozilla.org/en- US/docs/Web/API/Document_Object_Model/Introduction

Cross-Site Scripting (XSS) It is common to ask a user for text input and then display that input back to the screen. Think: product review, comment on an article, etc. If a user were to input JavaScript code, and that were to be displayed on the screen, what would happen? That JavaScript code would execute. What to do about it? Sanitize user input! Strip out any script tags or anything else that may be malicious. Client Side Security You can strip out the script tags using JavaScript, but you cannot rely on that as a full solution. You must also sanitize data at the server side because anyone can modify client-side data (using the same browser tools you use for debugging).

Regular Expressions Regular expressions are patterns used to match characters in a string. The simplest example of using regular expressions is when you want to restrict a user to typing in only numbers, or to following a particular pattern like an address or phone number. Regular expressions are heavily used in programming and learning how to use them is well worth your time if you want to be a developer. There are plenty of resources online. This page from Mozilla explains how to use them with JavaScript: