JAVA Script : Functions Ashima Wadhwa

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
JavaScript- Introduction. What it is and what it does? What it is? It is NOT Java It is NOT Server-side programming Users can see code It is a client-side.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
1 CS101 Introduction to Computing Lecture 32 Event Handling (Web Development Lecture 11)
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
1 Functions Lecfture Abstraction abstraction is the process of ignoring minutiae and focusing on the big picture in modern life, we are constantly.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
THINKING BIG Abstraction and Functions chapter 6 Modified by Dr. Paul Mullins for CPSC 130, F05.
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.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
JavaScript, Fourth Edition
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
1 JavaScript Part 3. Functions Allow the user to decide when a particular script should be run by the browser in stead of running as long as the page.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
1 JavaScript in Context. Server-Side Programming.
CIS 375—Web App Dev II JavaScript I. 2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
MTA EXAM HTML5 Application Development Fundamentals.
JavaScript 101 Lesson 6: Introduction to Functions.
JavaScript and Ajax Week 10 Web site:
4.1. Manage and maintain JavaScript Update the UI by using JavaScript. Understanding JavaScript and Coding Essentials.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
JavaScript Variables. Definition A variable is a "container" for information you want to store. A variable's value can change during the script.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Module 1 Introduction to JavaScript
Creating a Programmable Web Page
Java Script Introduction. Java Script Introduction.
>> Introduction to JavaScript
Web Systems & Technologies
Chapter 6 JavaScript: Introduction to Scripting
>> JavaScript: Location, Functions and Objects
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
Intro to JavaScript CS 1150 Spring 2017.
JavaScript Loops.
During the last lecture we discussed Functions & Variable Scope
JavaScript Syntax and Semantics
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
DHTML Javascript Internet Technology.
Your 1st Programming Assignment
Event Driven Programming & User Defined Functions
JavaScript – Part I Mendelsohn.
DHTML Javascript Internet Technology.
INFO/CSE 100, Spring 2005 Fluency in Information Technology
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript What is JavaScript? What can JavaScript do?
JavaScript MCS/BCS.
JavaScript What is JavaScript? What can JavaScript do?
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Topics Introduction to Functions Defining and Calling a Function
Tutorial 10: Programming with javascript
Javascript Chapter 19 and 20 5/3/2019.
CS105 Introduction to Computer Concepts JavaScript
Presentation transcript:

JAVA Script : Functions Ashima Wadhwa

Function A group of statements that is put together (or defined) once and then can be used (by reference) repeatedly on a Web page Also known as subprogram, procedure, subroutine

Advantages of Functions Number of lines of code is reduced Code becomes easier to read & understand Code becomes easier to maintain as changes need to be made only at a single location instead multiple locations

Function Identifiers The naming rules for function identifiers are the same as were discussed for variable and identifiers.

Creating JavaScript Functions function function_name(parameters) { JavaScript commands } parameters are the values sent to the function (note: not all functions require parameters) { and } are used to mark the beginning and end of the commands in the function.

Creating JavaScript Functions Function names are case-sensitive. The function name must begin with a letter or underscore ( _ ) and cannot contain any spaces. There is no limit to the number of function parameters that a function may contain. The parameters must be placed within parentheses, following the function name, and the parameters must be separated by commas.

Performing an Action with a Function <html> <body> <button onclick="myFunction()">Try it</button> <script> function myFunction() { alert("Hello\nHow are you?"); } </script> </body> </html>

Returning a Value from a Function To use a function to calculate a value use the return command along with a variable or value. function Area(Width, Length) { var Size = Width*Length; return Size; } the Area function calculates the area of a rectangular region and places the value in a variable named “Size” the value of the Size variable is returned by the function

Placing a Function in an HTML File The function definition must be placed before the command that calls the function. One convention is to place all of the function definitions in the <head> section. A function is executed only when called by another JavaScript command. It’s common practice for JavaScript programmers to create libraries of functions located in external files.

Two Ways of Calling Functions function popUp( message ) { window.alert( message ) ; } popUp( “Warning!” ) ; A function call appearing as a complete statement A function call appearing as part of a statement. Definitions of such functions include a ‘return’ statement function add( a, b ) { c = a + b ; return c ; } sum = add( 2, 4 ) ; document.write( sum ) ;

EXAMPLE 1 <html> <head> <script> function myFunction() { alert("Hello World!"); } </script> </head> <body> <button onclick="myFunction()">Try it</button> </body> </html>

EXAMPLE 2 <button onclick="myFunction('Harry Potter','Wizard')">Try it</button> <script> function myFunction(name,job) { alert("Welcome " + name + ", the " + job); } </script>