JavaScript: More Syntax and Using Events

Similar documents
JavaScript: More Syntax

PHP: More Syntax CISC 282 November 1, 2017

CS1520 Recitation Week 2

CSC Web Programming. Introduction to JavaScript

CGS 3066: Spring 2015 JavaScript Reference

Client-Side Web Technologies. JavaScript Part I

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

COMS 469: Interactive Media II

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

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

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

JavaScript: The Basics

DC71 INTERNET APPLICATIONS JUNE 2013

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

CHAPTER 6 JAVASCRIPT PART 1

PHP: The Basics CISC 282. October 18, Approach Thus Far

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

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

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

Catching Events. Bok, Jong Soon

Web Site Design and Development JavaScript

JavaScript Syntax. Web Authoring and Design. Benjamin Kenwright

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

Produced by. App Development & Modeling. BSc in Applied Computing. Eamonn de Leastar

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

CECS 189D EXAMINATION #1

Chapter 1 Introduction to Computers and the Internet

JavaScript CS 4640 Programming Languages for Web Applications

1. Cascading Style Sheet and JavaScript

Princess Nourah bint Abdulrahman University. Computer Sciences Department

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

UNIT-4 JAVASCRIPT. Prequisite HTML/XHTML. Origins

Outcomes Week 2 Overview Describe the inputs, activities, and outputs of each step in the software development life cycle. Describe arithmetic, relati

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript for C# Programmers Kevin

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

JavaScript. The Bad Parts. Patrick Behr

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

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

CS312: Programming Languages. Lecture 21: JavaScript

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

Chapter 3 Data Types and Variables

(Refer Slide Time: 01:40)

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

JavaScript. What s wrong with JavaScript?

Chapter 4 Basics of JavaScript

CSI 3140 WWW Structures, Techniques and Standards. Browsers and the DOM

EECS1012. Net-centric Introduction to Computing. Lecture Introduction to Javascript

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

AJAX: Introduction CISC 282 November 27, 2018

JavaScript: Introduction, Types

Information Design. Professor Danne Woo! infodesign.dannewoo.com! ARTS 269 Fall 2018 Friday 10:00PM 1:50PM I-Building 212

INF5750. Introduction to JavaScript and Node.js

JavaScript Basics. The Big Picture

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

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

JavaScript I Language Basics

4.1 Overview of JavaScript

Programming language components

Coding in JavaScript functions

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

Variables and Typing

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

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

JScript Reference. Contents

PHP. Interactive Web Systems

SEEM4570 System Design and Implementation Lecture 03 JavaScript

JavaScript code is inserted between tags, just like normal HTML tags:

AJAX: The Basics CISC 282 November 22, 2017

B l o c k B i n d i n g s

Chapter 2: Using Data

Scripting for Multimedia LECTURE 3: INTRODUCING JAVASCRIPT

5. Strict mode use strict ; 6. Statement without semicolon, with semicolon 7. Keywords 8. Variables var keyword and global scope variable 9.

COMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts

egrapher Language Reference Manual

AJAX: The Basics CISC 282 March 25, 2014

Here are the topics covered in this tutorial:

JavaScript: Sort of a Big Deal,

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

JavaScript: Coercion, Functions, Arrays

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

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

JQuery and Javascript

CISC 1600 Lecture 2.4 Introduction to JavaScript

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

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

Frontend II: Javascript and DOM Programming. Wednesday, January 7, 15

Chapter 17. Fundamental Concepts Expressed in JavaScript

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017

2D Game design Intro to Html 5

CSc 337 LECTURE 5: GRID LAYOUT AND JAVASCRIPT

JavaScript Lecture 2

JSF. JSF and Ajax Basics

Background. Javascript is not related to Java in anyway other than trying to get some free publicity

Operator overloading: extra examples

Microsoft Visual Basic 2005: Reloaded

What is PHP? [1] Figure 1 [1]

Transcription:

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? All declared variables have undefined as an initial value until another value is assigned 2

Some Handy Things typeof Operat that determines the type of a parameter Returns the type name as a String Can use typeof item typeof(item) Date Object with timing functions var localtime = new Date(); A Few Functions tolocalestring() getday(), getmonth(), getdate(), getfullyear() Result The current date and time as a String The current day of the week, month, day of the month and year gettime() The number of ms since Jan. 1, 1970 3 Dialogs alert(message) Displays message with an OK button confirm(message) Displays message with OK and Cancel buttons Returns true f OK, false f Cancel prompt(promptmsg, sampletext) Displays promptmsg with OK, Cancel and a text input box sampletext is optional; it is displayed in the input box Returns input f OK, null f Cancel 4

true and false Booleans true and false are truly so What is falsey? Something that evaluates to false but isn't really String "" (empty) Number 0 NaN, null and undefined What is truthy? Something that evaluates to true but isn't really All non-empty strings All non-zero numbers 5 Boolean Operats Operat Result Description x y x y x OR y x && y x y x AND y!x x NOT x Only use Boolean operands (x y) yields x if x is truthy; it yields y otherwise (x && y) yields x if x is falsey; it yields y otherwise 6

Testing Equivalence Operat Tests >, >= Greater than ( equal to) <, <= Less than ( equal to)!=, == (Not) equal to!==, === Strictly (not) equal to Standard equivalence operats perfms conversion e.g., 4 == "4" true Strict equivalence operats take type into account e.g., 4 === "4" false 7 if Statements if(condition) if(condition) else if (condition) else if(condition) else if(condition) else if (condition) 8

while and switch while(condition) do while(condition); switch(value) case value1: break;... case valuen: break; default: break; 9 Functions function name(parameter1,, parametern) return value; Function called with too many parameters? Extra parameters are igned Can access full list using arguments array Function called with too few parameters? Others are assigned values of undefined What if no return value is specified? Function returns undefined 10

Variable Scope: Implicit All implicitly-defined variables are global variables Can be used in any subsequent function statement Outside a function Inside a function Must be called first Inside any block Must be executed first x = 1; function scope() w = 2; f (y = 3; ) scope(); 11 Variable Scope: var Global variable if declared outside a function Local variable if declared inside a function Can only be used within that function Not restricted to declaring block (if applicable) var x = 1; function scope() var w = 2; f (var y = ) scope(); 12

Variable Scope: let Global variable if declared outside a function Local variable if declared inside a function Restricted to declaring block (if applicable) let x = 1; function scope() let w = 2; f (let y = ) scope(); 13 Arrays There are several ways to create an array var anarray = []; anarray[0] = 12; anarray[1] = "hello"; anarray[2] = (3 / 4); var anarray = new Array(1); anarray[0] = 12; anarray[2] = (3 / 4); anarray[1] = "hello"; var anarray = [12, 0.75, "hello"]; var anarray = new Array(12, 0.75, "hello"); Array size is dynamic Increases to accommodate largest index Some entries may be undefined 14

Some Array Functions Function concat(array1,, arrayn) push(value1,,valuen) unshift(value1,,valuen) shift() st() Result A single array fmed from the parameters Adds the given value(s) to the end of an array Adds the given value(s) to the front of an array Removes the first element of the array and returns it Sts the elements in an array 15 Best Practices Use semicolons to end statements They may be optional but they may cause issues if left out Explicitly declare all variables Avoid using global variables Comments are always imptant Use // f single lines Use /* */ f multiple lines 16

Events Browsing requires user interaction Move and click the mouse Load and leave websites Type in text boxes These actions are perceived as events Browser responds to such events HTML 4 defined a series of such events 18 in total 17 JavaScript and Events JavaScript can hook into browser events Create functions to respond to user actions Called event handlers Register the functions to events and elements Can be done in the HTML file <tag oneventname = "functionname()"></tag> functionname is called when eventname occurs f the given element This is an example of event-driven programming 18

Document Events Name The Document Must Applicable Elements load finish loading <body> unload* be left by the user <body> * suppt varies by the browser 19 Mouse Events Name The User Must Applicable Elements click click on the element Most dblclick double-click on the element Most mouseover move the mouse over the Most element mousemove move the mouse within the Most element mouseexit move the mouse away from the Most element mousedown press the mouse button Most mouseup release the mouse button Most 20