JavaScript Lecture 1

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

welcome to BOILERCAMP HOW TO WEB DEV

CGS 3066: Spring 2015 JavaScript Reference

Client-Side Web Technologies. JavaScript Part I

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

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

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications

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

CSC Web Programming. Introduction to JavaScript

JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology

This tutorial will help you understand JSON and its use within various programming languages such as PHP, PERL, Python, Ruby, Java, etc.

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

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

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

JavaScript: Sort of a Big Deal,

JavaScript I Language Basics


So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.

a Very Short Introduction to AngularJS

CSC 337. JavaScript Object Notation (JSON) Rick Mercer

JavaScript: Introduction, Types

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

Working with JavaScript

CS312: Programming Languages. Lecture 21: JavaScript

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

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

Typescript on LLVM Language Reference Manual

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

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

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

ECMA-404. The JSON Data Interchange Syntax. 2 nd Edition / December Reference number ECMA-123:2009

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

INF5750. Introduction to JavaScript and Node.js

Web Application Development

CSC Web Technologies, Spring Web Data Exchange Formats

JavaScript: Coercion, Functions, Arrays

Lecture 8 (7.5?): Javascript

JavaScript: The Basics

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

JME Language Reference Manual

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

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

Chapter 3 Data Types and Variables

Programming Language Basics

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

Full file at

Cleveland State University Department of Electrical and Computer Engineering. CIS 408: Internet Computing

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

JavaScript. The Bad Parts. Patrick Behr

Flat triples approach to RDF graphs in JSON

JavaScript Lecture 2

Kyle Rainville Littleton Coin Company

Language Fundamentals Summary

Basics of Java Programming

LOON. Language Reference Manual THE LANGUAGE OF OBJECT NOTATION. Kyle Hughes, Jack Ricci, Chelci Houston-Borroughs, Niles Christensen, Habin Lee

JSON Evaluation. User Store

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

Chapter 2 Working with Data Types and Operators

Principles of Programming Languages

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017

Objects and Classes Lecture 2

Tamarin and ECMAScript 4. John Resig (ejohn.org) Mozilla Corporation

Chapter 2: Using Data

Variables and Typing

Programming with Java

CS 130(0) JavaScript Lab

Such JavaScript Very Wow

COMS 469: Interactive Media II

[301] JSON. Tyler Caraza-Harter

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

Java Notes. 10th ICSE. Saravanan Ganesh

Full file at

VARIABLES AND TYPES CITS1001

HTML5 and CSS3 More JavaScript Page 1

Java Bytecode (binary file)

Scripting for Multimedia LECTURE 5: INTRODUCING CSS3

Sprite an animation manipulation language Language Reference Manual

Values and Variables 1 / 30

Objects and Classes Lecture 1

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

Data Visualization (CIS/DSC 468)

Grading for Assignment #1

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

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

Web UI. Survey of Front End Technologies. Web Challenges and Constraints. Desktop and mobile devices. Highly variable runtime environment

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

Java Programming Basics. COMP 401, Spring 2017 Lecture 2

Introduction to Java

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Key Differences Between Python and Java

Lesson: Web Programming(4) Omid Jafarinezhad Sharif University of Technology

JavaScript Programming

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Internet Engineering Task Force (IETF) Obsoletes: 4627, 7158 March 2014 Category: Standards Track ISSN:

AIM. 10 September

Lecture Set 2: Starting Java

CISC 1600 Lecture 2.4 Introduction to JavaScript

Transcription:

JavaScript Lecture 1 Waterford Institute of Technology May 17, 2016 John Fitzgerald Waterford Institute of Technology, JavaScriptLecture 1 1/31

Javascript Extent of this course A condensed basic JavaScript course All necessary materials provided as presentations and labs Not using frameworks One or more external JavaScript files Focus on client-side usage Introduces the popular jquery JavaScript library Explores the Document Object Model (DOM) Introduces Ajax update specific parts of web page avoids complete page refresh Code developed on WebStorm IDE using Airbnb styling Waterford Institute of Technology, JavaScriptLecture 1 2/31

JavaScript Introduction Topics discussed this presentation Brief introduction to and history of language Roles of the language Its data types JavaScript Object Notation (JSON) Simple program employing JavaScript Waterford Institute of Technology, JavaScriptLecture 1 3/31

Javascript Overview Originally a small language Not anymore - now enormous Flawed but powerful Not Java Not a subset of Java Very different languages Shares C-family syntax Similarities Scheme & Self Scores of badly written books aimed at the dummies and amateur market Waterford Institute of Technology, JavaScriptLecture 1 4/31

Javascript Language specification growth Waterford Institute of Technology, JavaScriptLecture 1 5/31

Ecma International ECMAScript - the language of the web ECMAScript: standardization body Several popular implementations: JavaScript JScript ActionScript Edition 6 (ES6) published June 2015 Course applies ES6 Waterford Institute of Technology, JavaScriptLecture 1 6/31

JavaScript Several frameworks available Client-side Angular Backbone Ember Server-side node.js io.js hapi.js MEAN stack collection: MongoDB Express.js Angular Node.js Waterford Institute of Technology, JavaScriptLecture 1 7/31

Nature of JavaScript Structure Client-Side Web Waterford Institute of Technology, JavaScriptLecture 1 8/31

Nature of JavaScript Structure Client-Side Web Waterford Institute of Technology, JavaScriptLecture 1 9/31

Nature of JavaScript The Language Although not Java, has: Similar syntax & keywords Similar standard library naming conventions Object oriented but does not have classes in classical sense. uses syntactic sugar to simulate classes prototypal: objects inherit from objects Dynamic typing Variable may be reference to object of any type Waterford Institute of Technology, JavaScriptLecture 1 10/31

Javascript Styling Our choice from several available Style Guides and IDEs Airbnb JavaScript Style Guide WebStorm JavaScript IDE Waterford Institute of Technology, JavaScriptLecture 1 11/31

Nature of JavaScript The Language Provides access to main components web page: Cascade Style Sheet (CSS) properties Markup content (e.g.: div, img, p) Forms (Communication to server) Most often used client-side Growing use server-side (node.js) Weakly typed with first-class functions function: block reusable code (more on this later) functions are objects may be passed as parameters Waterford Institute of Technology, JavaScriptLecture 1 12/31

Javascript Primitive Data Types Six primitive types boolean number string null undefined symbol (ES6) All other types are objects console.log('this is a string'); console.log('true is a boolean'); console.log('10.5 is a number'); Waterford Institute of Technology, JavaScriptLecture 1 13/31

Javascript Primitive Wrapper Data Types Four wrapper types Boolean Number String Symbol // Wrapper's valueof returns primitive value. const b = Boolean(true); // b => true. Waterford Institute of Technology, JavaScriptLecture 1 14/31

var, const and let A necessary preview var, const and let used to store values and object references: var exists since ES1. const & let introduced ES6. Significant behavioural differences. Preference given henceforth to use of const, then let. var usage should be avoided. var x = 10; // Avoid future use let y = 20; // Use where reassign likely const z = 30; // Not garbage collected Waterford Institute of Technology, JavaScriptLecture 1 15/31

Data types boolean boolean can be true false // Output: b is true const b = true; if (b) { console.log('b is true'); }; // Ouput: b is true const b = true; if (b) { console.log('b is ', Boolean(b)); }; Waterford Institute of Technology, JavaScriptLecture 1 16/31

Data types number number 64-bit floating point Similar to Java s double No integer type number type includes NaN Infinity Problematic in finance 0.1 + 0.2 == 0.3 This expression false // Output is 3.3333333333333335 const val = 10 / 3; console.log(val); // Output: true. val is not a number const val = '2005/12/12'; console.log(isnan(val)); // true // Output: string console.log(typeof val); const val = 10 / 0; console.log(val); // Infinity console.log(typeof val); // number Waterford Institute of Technology, JavaScriptLecture 1 17/31

Data types string string sequence of zero or more Unicode characters. Similar to Java String. No char type as in Java. Literals use or " to enclose characters Either quote type may be used in pairs. Illegal to mix. Important: Use only single quotes to comply with style guide. 'This is a string.' "This is also a string but we will not use double quotes." "This is not a legal string' Waterford Institute of Technology, JavaScriptLecture 1 18/31

Data types string Internal quotes Use escape sequence \ const s = 'What\'s a \"celeb\" famous for?'; // What's a "celeb" famous for? console.log(s); Waterford Institute of Technology, JavaScriptLecture 1 19/31

Data types null & undefined Variable not assigned a value is of type undefined null indicates the absence of a value Value null is a literal typeof null returns object This is an error in the language Some experienced developers no longer use null. var planes; // => undefined // A language error in ES5, fixed ES6 console.log(typeof planes); // => object in ES5 const planes; // Uncaught SyntaxError: Missing initializer in const declaration Waterford Institute of Technology, JavaScriptLecture 1 20/31

Data types symbol Associated wrapper class Symbol Introduced in ES6 Can generate unique property keys Eliminates risk collision let uniquekey = Symbol(); obj = {}; obj[uniquekey] = 'unique'; console.log(obj[uniquekey]); // => unique console.log(uniquekey); // => Symbol() console.log(typeof (uniquekey)); // => symbol Waterford Institute of Technology, JavaScriptLecture 1 21/31

Data types Object Object literal comma-separated list of colon-separated name:value pairs in curly braces. const book = { title: 'Java', author: 'Chapman', ISBN: 'ISBN 10 03219804333', edition: 4, isinprint: true, }; book.isinprint // => true Waterford Institute of Technology, JavaScriptLecture 1 22/31

Data types Object Container comprising name-value pairs value may be object may add new properties anytime const book = { title: 'Java', author: { name: 'Simpson', } }; console.log(book.title); // => Java // Add new property (name value pair) book.isbn = 'ISBN 10 03219804333'; Waterford Institute of Technology, JavaScriptLecture 1 23/31

Semicolon insertion Example where positioning of curly brace matters Waterford Institute of Technology, JavaScriptLecture 1 24/31

Semicolon insertion Example where positioning of curly brace matters Waterford Institute of Technology, JavaScriptLecture 1 25/31

JavaScript Run Program - Simple Example / A Web Page with HTML & reference to external JavaScript file / <!DOCTYPE html> <html> <head> <meta charset="utf 8"> </head> <body> <h1 id="hello">hello ICTSkills</h1> <script src="js/foo.js"></script> </body> </html> Waterford Institute of Technology, JavaScriptLecture 1 26/31

JavaScript Run Program - Simple Example / Demo JavaScript code / alert('hello ICTSkills'); function foo() { const size = 3; for (let i = 0; i < size; i += 1) { console.log(i); } } foo(); Waterford Institute of Technology, JavaScriptLecture 1 27/31

JavaScript Run Program - Simple Example Waterford Institute of Technology, JavaScriptLecture 1 28/31

JavaScript Run Program - Simple Example Waterford Institute of Technology, JavaScriptLecture 1 29/31

JavaScript Run Program - Simple Example Waterford Institute of Technology, JavaScriptLecture 1 30/31

Waterford Institute of Technology, JavaScriptLecture 1 31/31