JavaScript Introduction

Similar documents
SEEM4570 System Design and Implementation Lecture 03 JavaScript

JavaScript Specialist v2.0 Exam 1D0-735

Such JavaScript Very Wow

INDEX SYMBOLS See also

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

CSC Javascript

Client vs Server Scripting

CGS 3066: Spring 2015 JavaScript Reference

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

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

JAVASCRIPT. JavaScript is the programming language of HTML and the Web. JavaScript Java. JavaScript is interpreted by the browser.

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

Working with JavaScript

Princess Nourah bint Abdulrahman University. Computer Sciences Department

The first sample. What is JavaScript?

CSC Web Programming. Introduction to JavaScript

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

JavaScript CS 4640 Programming Languages for Web Applications

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser:

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

Web Designing Course

JavaScript: The Basics

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

JavaScript CS 4640 Programming Languages for Web Applications

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

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

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

User Interaction: jquery

CS Final Exam Review Suggestions - Spring 2018

COMS 469: Interactive Media II

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

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

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

JScript Reference. Contents

JavaScript. The Bad Parts. Patrick Behr

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

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

XML JavaScript Object Notation JSON Cookies Miscellaneous What Javascript can t do. OOP Concepts of JS

E ECMAScript, 21 elements collection, HTML, 30 31, 31. Index 161

CS312: Programming Languages. Lecture 21: JavaScript

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

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

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

INLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT

INF5750. Introduction to JavaScript and Node.js

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

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

Standard 1 The student will author web pages using the HyperText Markup Language (HTML)

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Javascript. Many examples from Kyle Simpson: Scope and Closures

Client-Side Web Technologies. JavaScript Part I

JavaScript Basics. Mendel Rosenblum. CS142 Lecture Notes - JavaScript Basics

Lecture 8 (7.5?): Javascript

Fundamentals of Website Development

Web Programming/Scripting: JavaScript

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard

JavaScript: Introduction, Types

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

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

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

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

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

! The final is at 10:30 am, Sat 6/4, in this room. ! Open book, open notes. ! No electronic devices. ! No food. ! Assignment 7 due 10pm tomorrow

JavaScript. What s wrong with JavaScript?

CE212 Web Application Programming Part 2

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

Session 6. JavaScript Part 1. Reading

CHAPTER 6 JAVASCRIPT PART 1

HTML5. HTML5 Introduction. Form Input Types. Semantic Elements. Form Attributes. Form Elements. Month Number Range Search Tel Url Time Week

CISC 1600 Lecture 2.4 Introduction to JavaScript

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

By the end of this section of the practical, the students should be able to:

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

PHP / MYSQL DURATION: 2 MONTHS

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

JavaScript Programming

Ajax HTML5 Cookies. Sessions 1A and 1B

Elementary Computing CSC 100. M. Cheng, Computer Science

Web Development & Design Foundations with HTML5

COMS 469: Interactive Media II

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

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

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

P a g e 1. Danish Technological Institute. Scripting and Web Languages Online Course k Scripting and Web Languages

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

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

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

ArcGIS API for JavaScript: Using Arcade with your Apps. Kristian Ekenes & David Bayer

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

Basics of Web Technologies

WebGL Seminar: O3D. Alexander Lokhman Tampere University of Technology

jquery and AJAX

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

JAVASCRIPT BASICS. JavaScript String Functions. Here is the basic condition you have to follow. If you start a string with

CITS3403 Agile Web Development Semester 1, 2018

IN Development in Platform Ecosystems Lecture 2: HTML, CSS, JavaScript

5. JavaScript Basics

The JavaScript Language

Transcription:

JavaScript Introduction Web Technologies I. Zsolt Tóth University of Miskolc 2016 Zsolt Tóth (UM) JavaScript Introduction 2016 1 / 31

Introduction Table of Contents 1 Introduction 2 Syntax Variables Control Flow Statements Functions 3 {B,D}OM Document Object Model Browser Object Model Zsolt Tóth (UM) JavaScript Introduction 2016 2 / 31

Introduction JavaScript untyped high level Object based Not object oriented Script language Client side Browser interprets + Simple + Easy-to-learn + Form checking / validation + Animated elements + AJAX + JSON Processing - Security Zsolt Tóth (UM) JavaScript Introduction 2016 3 / 31

Introduction History 1995 May Netscape Mocha 1995 Sept Mocha LiveScript 1995 Dec LiveScript JavaScript 1998 Standardization ISO Standard JQuery JavaScript Object Notation TypeScript AngularJS Zsolt Tóth (UM) JavaScript Introduction 2016 4 / 31

Introduction Usage HTML document <script> tag Within HTML <head> <body> External file *.js linking function definitions C, Java like syntax < s c r i p t src =" myscript. j s " > </ s c r i p t > < s c r i p t > a l e r t ( "My F i r s t JavaScript " ) ; </ s c r i p t > Zsolt Tóth (UM) JavaScript Introduction 2016 5 / 31

Introduction Events onload onsubmit onchange onkeydown onkeyup onclick ondbclick <body onload =" a l e r t ( Hello World! ) " >... </ body> Zsolt Tóth (UM) JavaScript Introduction 2016 6 / 31

Table of Contents Syntax Variables 1 Introduction 2 Syntax Variables Control Flow Statements Functions 3 {B,D}OM Document Object Model Browser Object Model Zsolt Tóth (UM) JavaScript Introduction 2016 7 / 31

Syntax Variables Definition untyped var Starts with character, $, _ Case-sensitive undefined null js > x = 5 ; 5 js > y = " 5 " ; 5 js > y = x + y ; 55 js > Zsolt Tóth (UM) JavaScript Introduction 2016 8 / 31

Syntax Variables String, Number, Boolean String " Captain Jack Sparrow" "Captain" Jack Sparrow Number 42, 42.00 3.1415e3 = 3141.5 3.1415e-1 = 0.31415 Boolean true false x =1; 1 js > y = t r u e ; t r u e js > x + y 2 x y 0 js > Zsolt Tóth (UM) JavaScript Introduction 2016 9 / 31

Syntax Variables Arrays index between 0 and n-1 array[index] Contains Simple types Arrays Objects Functions js > var cars = [ " t r a b a n t ", "bmw " ] ; js > cars trabant,bmw js > cars [ 5 ] = " panda " panda js > cars trabant,bmw,,,, panda js > Zsolt Tóth (UM) JavaScript Introduction 2016 10 / 31

Syntax Variables Obejcts data structure. operator Variables (fields) Methods var person=new Object ( ) ; person. f i r s t n a m e =" John " ; person. lastname ="Doe " ; person. age =50; person. eyecolor =" blue " ; Zsolt Tóth (UM) JavaScript Introduction 2016 11 / 31

Syntax Variables API Objects Math Basic mathematical functions and constants round() random() [0,1] sqrt() max() min() PI E Date new Date(); Current date ms 1970-01-01 var d = new Date ( ) ; a l e r t ( d + 7 ) ; Zsolt Tóth (UM) JavaScript Introduction 2016 12 / 31

Syntax Variables API Objects String str[3] "alma".length = 4 Escape sequences indexof() match() replace() touppercase() tolowercase() split() trim() RegExp Pattern recognition /pattern/modifier new RegExp(pattern, modifier); Examples [abc], [ abc], [A-Z], [0-9], (a b c),.,\s *,+,? {n}, {n,m} Modifiers test() i case insensitive g global search JavaScript m multiline Zsolt Tóth (UM) JavaScript Introduction 2016 13 / 31

Table of Contents Syntax Control Flow Statements 1 Introduction 2 Syntax Variables Control Flow Statements Functions 3 {B,D}OM Document Object Model Browser Object Model Zsolt Tóth (UM) JavaScript Introduction 2016 14 / 31

Syntax Control Flow Statements if, switch if (condition) {...} if (condition) {...} else {...} else if block condition? true : false; break! Number Char switch ( n ) { case 0:... break ; case 1:... break ; d e f a u l t :... } Zsolt Tóth (UM) JavaScript Introduction 2016 15 / 31

Syntax Control Flow Statements Conditions == Value === Value and type!= Not equals!== Not equals or different type <,<=,>,>= less, more, etc. && and or! negation Zsolt Tóth (UM) JavaScript Introduction 2016 16 / 31

for Syntax Control Flow Statements Iterative Parameters 1 Initialization 2 Condition 3 Incrementation f o r ( i = 0; i < 5; i ++) {... } Arrays Object properties f o r ( var x i n obj ) {... } Zsolt Tóth (UM) JavaScript Introduction 2016 17 / 31

while, do... while Syntax Control Flow Statements while ( c o n d i t i o n ) {... } do {... } while ( c o n d i t i o n ) ; Zsolt Tóth (UM) JavaScript Introduction 2016 18 / 31

Syntax Control Flow Statements break, continue break loops switch label goto label! continue loops goto end of the loop loop does not break! Zsolt Tóth (UM) JavaScript Introduction 2016 19 / 31

Table of Contents Syntax Functions 1 Introduction 2 Syntax Variables Control Flow Statements Functions 3 {B,D}OM Document Object Model Browser Object Model Zsolt Tóth (UM) JavaScript Introduction 2016 20 / 31

Syntax Functions Function Definition Untyped parameters? return type? return? f u n c t i o n sayhello ( ) { a l e r t ( Hello World! ) ; } Zsolt Tóth (UM) JavaScript Introduction 2016 21 / 31

Syntax Functions Parameters enumerate variables, Type is not defined Variable names a, b, c X name, job, grosssalary f u n c t i o n add ( a, b ) { a l e r t ( a + b ) ; } Zsolt Tóth (UM) JavaScript Introduction 2016 22 / 31

Syntax Functions Return Type Untyped! Function can return with Simple type Array Object Function Choose function names wisely. f u n c t i o n f a c t ( n ) { i f ( n <= 1) { r e t u r n 1; } r e t u r n n f a c t ( n 1); } Zsolt Tóth (UM) JavaScript Introduction 2016 23 / 31

Syntax Functions Closure Programming technique Anonymous function Record stores a function Function as a variable Event handling var add = ( f u n c t i o n ( ) { var counter = 0; r e t u r n f u n c t i o n ( ) { r e t u r n counter += 1; } } ) ( ) ; Zsolt Tóth (UM) JavaScript Introduction 2016 24 / 31

Syntax Functions Callback Functions Function as a parameter Expected behavior Generalization Event handling $ ( document ). ready ( f u n c t i o n ( ) { a l e r t ( document i s ready! ) ; } ) ; Zsolt Tóth (UM) JavaScript Introduction 2016 25 / 31

Tartalomjegyzék {B,D}OM Document Object Model 1 Introduction 2 Syntax Variables Control Flow Statements Functions 3 {B,D}OM Document Object Model Browser Object Model Zsolt Tóth (UM) JavaScript Introduction 2016 26 / 31

{B,D}OM Document Object Model Hyerarchical Datamodel PCR Containing relationship Tree-structure Describes HTML documents Nodes are objects API Zsolt Tóth (UM) JavaScript Introduction 2016 27 / 31

Document Object Model {B,D}OM Document Object Model Zsolt Tóth (UM) JavaScript Introduction 2016 28 / 31

{B,D}OM Document Object Model document document HTML elements query modification appending Methods getelementbyid() getelementsbytagname() createelement() appendchild() removechild() Attributes forms[] innerhtml attribute style onclick Zsolt Tóth (UM) JavaScript Introduction 2016 29 / 31

Table of Contents {B,D}OM Browser Object Model 1 Introduction 2 Syntax Variables Control Flow Statements Functions 3 {B,D}OM Document Object Model Browser Object Model Zsolt Tóth (UM) JavaScript Introduction 2016 30 / 31

{B,D}OM Browser Object Model Browser Object Model Repreents the browsers state one browser many documents window History history navigator alert() cookie Zsolt Tóth (UM) JavaScript Introduction 2016 31 / 31