JavaScript. Like PHP, JavaScript is a modern programming language that is derived from the syntax at C.

Similar documents
PHP Syntax. PHP is a great example of a commonly-used modern programming language.

week8 Tommy MacWilliam week8 October 31, 2011

Understanding Angular Directives By Jeffry Houser

Pointers in C/C++ 1 Memory Addresses 2

React. HTML code is made up of tags. In the example below, <head> is an opening tag and </head> is the matching closing tag.

CSC 337. JavaScript Object Notation (JSON) Rick Mercer

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

JavaScript CS 4640 Programming Languages for Web Applications

View a Students Schedule Through Student Services Trigger:

Structures and Pointers

DECISION CONTROL AND LOOPING STATEMENTS

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

JavaScript CS 4640 Programming Languages for Web Applications

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

1/22/2017. Chapter 2. Functions and Control Structures. Calling Functions. Objectives. Defining Functions (continued) Defining Functions


<form>. input elements. </form>

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

INTRODUCTION TO JAVASCRIPT

Other conditional and loop constructs. Fundamentals of Computer Science Keith Vertanen

CIW 1D CIW JavaScript Specialist.

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

IN4MATX 133: User Interface Software

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

Haskell Making Our Own Types and Typeclasses

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Lesson 6: Introduction to Functions

Agenda: Discussion Week 7. May 11, 2009

CGS 3066: Spring 2015 JavaScript Reference

op5 Trapper 1.0 Administrator s Manual

Lecture 3. The syntax for accessing a struct member is

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

Number Review. Lecture #3 More C intro, C Strings, Arrays, & Malloc Variables. Clarification about counting down

Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172. In compensation, no class on Friday, Jan. 31.

Objectives. Describe ways to create constants const readonly enum

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

ORB Education Quality Teaching Resources

CSC Web Programming. Introduction to JavaScript

JavaScript: Introduction, Types

22c:111 Programming Language Concepts. Fall Types I

Lecture Outline. Rainfall Solution Attempt 1. Motivation for arrays. Introducing the Array. Motivation

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

Introduction to Python

ACT! Calendar to Excel

Boolean Data-Type. Boolean Data Type (false, true) i.e. 3/6/2018. The type bool is also described as being an integer: bool bflag; bflag = true;

Basic Design for Developers. Ma. Andrea Drei R. Alquiros Design Team Lead, Lendsoft Solutions, Inc.

PHP by Pearson Education, Inc. All Rights Reserved.

BOOSTING THE SECURITY

Novell Sample Paper. 1. On December 31, which ships will be sailing from the Port on a New Year's Eve.

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

Lecture 4. Wednesday, January 27, 2016

EECS402 Lecture 24. Something New (Sort Of) Intro To Function Pointers

Institute For Arts & Digital Sciences SHORT COURSES

Intro. Scheme Basics. scm> 5 5. scm>

COMS 469: Interactive Media II

CONTENTS: Arrays Strings. COMP-202 Unit 5: Loops in Practice

Functions. Functions in JavaScript are declared using the function keyword

JavaScript Introduction

Mouse-over Effects. Text based buttons

Arrays (Lists) # or, = ("first string", "2nd string", 123);

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

Introduction to Web Development

News. CSE 130: Programming Languages. Environments & Closures. Functions are first-class values. Recap: Functions as first-class values

Programming Karel the Robot

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

CS349/SE382 A1 C Programming Tutorial

ITS331 Information Technology I Laboratory

SEEM4570 System Design and Implementation Lecture 03 JavaScript

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

In this chapter then, you ll learn the following:

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers

CHAPTER : 9 FLOW OF CONTROL

Once Written, Twice Applied: The Basics of Array Processing In SAS Elizabeth A. Roth, RAND Corporation, Santa Monica, CA

Creating a File and Folder Backup

ESIGATE MODULE DOCUMENTATION DIGITAL EXPERIENCE MANAGER 7.2

REST. Web-based APIs

MULTIMEDIA AND WEB TECHNOLOGY

JavaScript Programming

(Refer Slide Time: 01:40)

PROGRAMMING FUNDAMENTALS

CS50 Quiz Review. November 13, 2017

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

IT150/IT152 Concepts Summary Sheet

Working with Database. Client-server sides AJAX JSON Data formats Working with JSON data Request Response Bytes Database

Novell Sample Papers

EuroForth Forth Query Language (FQL) - Implementation and Experience

DATA VISUALIZATION Prepare the data for visualization Data presentation architecture (DPA) is a skill-set that seeks to identify, locate, manipulate,

PIC 40A. Review for the Final. Copyright 2011 Jukka Virtanen UCLA 1 06/05/15

Programming Languages and Techniques (CIS120)

Chapter 3, Selection. Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved.

CS61C : Machine Structures

Armstrong State University Engineering Studies MATLAB Marina Switch-Case Statements Primer

Programming Languages and Techniques (CIS120)

Lab 7 Macros, Modules, Data Access Pages and Internet Summary Macros: How to Create and Run Modules vs. Macros 1. Jumping to Internet

CallPilot Multimedia Messaging

Enters system mode. Example The following example creates a scheduler named maintenancesched and commits the transaction:

Transcription:

Like PHP, JavaScript is a modern programming language that is derived from the syntax at C. It has been around just about as long as PHP, also having been invented in 1995. JavaScript, HTML, and CSS make up the three languages defining most of the user experience on the web.

To start writing JavaScript, open up a file with the.js file extension. No need for any code delimiters like we had in PHP. Our website will know that our file is JavaScript because we ll explicitly tell it as much in an HTML tag. Unlike PHP which runs server-side, JavaScript applications run client-side, on your own machine.

Including JavaScript in your HTML Just like CSS with <style> tags, you can directly write your JavaScript between <script> tags. Just like CSS with <link> tags, you can write your JavaScript in separate files and link them in by using the src attribute of the <script> tag.

Including JavaScript in your HTML Just like CSS with <style> tags, you can directly write your JavaScript between <script> tags. Just like CSS with <link> tags, you can write your JavaScript in separate files and link them in by using the src attribute of the <script> tag.

Variables JavaScript variables are similar to PHP variables. No type specifier. When a local variable is first declared, preface with the var keyword.

Variables JavaScript variables are similar to PHP variables. No type specifier. When a local variable is first declared, preface with the var keyword. $x = 44;

Variables JavaScript variables are similar to PHP variables. No type specifier. When a local variable is first declared, preface with the var keyword. $x = 44;

Variables JavaScript variables are similar to PHP variables. No type specifier. When a local variable is first declared, preface with the var keyword. var x = 44;

Conditionals All of the old favorites from C are still available for you to use. if

Conditionals All of the old favorites from C are still available for you to use. if else if

Conditionals All of the old favorites from C are still available for you to use. if else if else

Conditionals All of the old favorites from C are still available for you to use. if else if else switch

Conditionals All of the old favorites from C are still available for you to use. if else if else switch?:

Loops All of the old favorites from C are still available for you to use.

Loops All of the old favorites from C are still available for you to use. while

Loops All of the old favorites from C are still available for you to use. while do-while

Loops All of the old favorites from C are still available for you to use. while do-while for

Functions All functions are introduced with the function keyword. JavaScript functions, particularly those bound specifically to HTML elements, can be anonymous you don t have to give them a name! We ll revisit anonymity a little later, and we ll revisit binding to HTML elements in the video on the Document Object Model.

Arrays Declaring an array is pretty straightforward.

Arrays Declaring an array is pretty straightforward. var nums = [1, 2, 3, 4, 5];

Arrays Declaring an array is pretty straightforward. var nums = [1, 2, 3, 4, 5]; var mixed = [1, true, 3.333, five ];

Objects JavaScript has the ability to behave as an object-oriented programming language. By contrast, C is a functional programming language. JavaScript can behave like a functional programming language, too. An object is sort of analogous to a C structure.

Objects C structures contain a number of fields, which we might also call properties. But the properties themselves can not ever stand on their own.

Objects struct car { int year; char model[10]; } C structures contain a number of fields, which we might also call properties. But the properties themselves can not ever stand on their own.

Objects struct car { int year; char model[10]; } C structures contain a number of fields, which we might also call properties. But the properties themselves can not ever stand on their own. struct car herbie;

Objects struct car { int year; char model[10]; } C structures contain a number of fields, which we might also call properties. But the properties themselves can not ever stand on their own. struct car herbie; herbie.year = 1963; herbie.model = Beetle ;

Objects struct car { int year; char model[10]; } C structures contain a number of fields, which we might also call properties. But the properties themselves can not ever stand on their own. struct car herbie; year = 1963; model = Beetle ;

Objects struct car { int year; char model[10]; } C structures contain a number of fields, which we might also call properties. But the properties themselves can not ever stand on their own. struct car herbie; year = 1963; model = Beetle ;

Objects C structures contain a number of fields, which we might also call properties. But the properties themselves can not ever stand on their own. Objects, meanwhile, have properties but also methods, or functions that are inherent to the object, and mean nothing outside of it. Thus, like properties can methods not ever stand on their own.

Objects function(object);

Objects function(object);

Objects object.function();

Objects The fields and methods of an object are similar in spirit to the idea of an associative array, with which we re familiar from PHP.

Objects The fields and methods of an object are similar in spirit to the idea of an associative array, with which we re familiar from PHP. var herbie = {year : 1963, model: Beetle };

Loops (redux) How do we iterate across all of the key-value pairs of an object (or indeed, all of the elements of an array)?

Loops (redux) How do we iterate across all of the key-value pairs of an object (or indeed, all of the elements of an array)? foreach($array as $key) { // use $key in here as a stand-in for $array[$i] }

Loops (redux) How do we iterate across all of the key-value pairs of an object (or indeed, all of the elements of an array)? foreach($array as $key) { // use $key in here as a stand-in for $array[$i] }

Loops (redux) How do we iterate across all of the key-value pairs of an object (or indeed, all of the elements of an array)? for (var key in object) { // use object[key] in here }

Loops (redux) How do we iterate across all of the key-value pairs of an object (or indeed, all of the elements of an array)? for (var key of object) { // use key in here }

Loops (redux) var wkarray = [ Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday ];

Loops (redux) var wkarray = [ Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday ]; for (var day in wkarray) { console.log(day); }

Loops (redux) var wkarray = [ Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday ]; for (var day of wkarray) { console.log(day); }

Printing and variable interpolation console.log(wkarray[day]. is day number. (day + 1). of the week! );

Printing and variable interpolation console.log(wkarray[day] + is day number + (day + 1) + of the week! );

Printing and variable interpolation console.log(wkarray[day] + is day number + (day + 1) + of the week! );

Printing and variable interpolation console.log(wkarray[day] + is day number + (parseint(day) + 1) + of the week! );

Functions (redux) Arrays are a special case of an object (in fact, everything in JavaScript is a special case of an object), and has numerous methods that can applied to them: array.size(), array.pop(), array.push(x), array.shift(); There is also a method for arrays called map(), which can be used to apply a function to all elements of an array. A great situation to use an anonymous function

Functions (redux) var nums = [1, 2, 3, 4, 5];

Functions (redux) var nums = [1, 2, 3, 4, 5]; nums = nums.map(function(num) { return num * 2; });

Functions (redux) var nums = [1, 2, 3, 4, 5]; nums = nums.map(function(num) { return num * 2; });

Functions (redux) var nums = [2, 4, 6, 8, 10]; nums = nums.map(function(num) { return num * 2; });

Events An event in HTML and JavaScript is a response to user interaction with the web page. A user clicks a button, a page has finished loading, a user has hovered over a portion of the page, the user typed in an input field. JavaScript has support for event handlers, which are callback functions that respond to HTML events. Many HTML elements have support for events as an attribute.

<html> </html> <head> </head> <body> <title>event Handlers</title> <button onclick= >Button 1</button> <button onclick= >Button 2</button> </body>

<html> </html> <head> </head> <body> <title>event Handlers</title> <button onclick= >Button 1</button> <button onclick= >Button 2</button> </body>

Events We can write a generic event handler in JavaScript, creating an event object, that will tell us which of these two buttons was clicked.

<html> </html> <head> </head> <body> <title>event Handlers</title> <button onclick= alertname(event) >Button 1</button> <button onclick= alertname(event) >Button 2</button> </body>

function alertname(event) { var trigger = event.srcelement; alert( You clicked on + trigger.innerhtml); }

function alertname(event) { var trigger = event.srcelement; alert( You clicked on + trigger.innerhtml); }

function alertname(event) { var trigger = event.srcelement; alert( You clicked on + trigger.innerhtml); }