INF5750. Introduction to JavaScript and Node.js

Similar documents
JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications

Working with JavaScript

CS312: Programming Languages. Lecture 21: JavaScript

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

Javascript. Many examples from Kyle Simpson: Scope and Closures

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

JavaScript: Sort of a Big Deal,

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. History. Adding JavaScript to a page. CS144: Web Applications

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

Boot Camp JavaScript Sioux, March 31, 2011

Node.js Training JavaScript. Richard richardrodger.com

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains an Individual and Group component

FALL 2017 CS 498RK JAVASCRIPT. Fashionable and Functional!

JavaScript. The Bad Parts. Patrick Behr

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

ECMAScript 2015 The Future of JavaScript is Now!

JavaScript: Introduction, Types

JavaScript: The Basics

JS Event Loop, Promises, Async Await etc. Slava Kim

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

JavaScript I Language Basics

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

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

Client-Side Web Technologies. JavaScript Part I

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

CSC Web Programming. Introduction to JavaScript

Node.js I Getting Started

Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

JavaScript Lecture 1

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

TypeScript. Types. CS144: Web Applications

ECMAScript 2015 and beyond The Future of JavaScript is Now!

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

Session 6. JavaScript Part 1. Reading

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

Angular 2 Programming

WebStorm, intelligent IDE for JavaScript development

CHAPTER 6 JAVASCRIPT PART 1

Introduction to Programming Using Java (98-388)

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

JavaScript: the Big Picture

JavaScript: Coercion, Functions, Arrays

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

Lecture 8 (7.5?): Javascript

JavaScript for C# Programmers Kevin

JavaScript: Getting Started

JavaScript: Features, Trends, and Static Analysis

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

Node.js. Node.js Overview. CS144: Web Applications

JavaScript Introduction

Module 6 Node.js and Socket.IO

Comprehensive AngularJS Programming (5 Days)

Advance Mobile& Web Application development using Angular and Native Script

J, K, L. Node.js require() method, 403 package.json, 401 streams functionality, 401 task() method, 401 use strict statement, 403

ECMAScript 6 The Future of JavaScript is Now!

Web Application Development

JAVASCRIPT FOR THE C# DEVELOPER

VS005 - Cordova vs NativeScript

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

Rhino & RingoJS: JavaScript on the JVM

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

Client vs Server Scripting

The results for a few specific cases below are indicated. allequal ([1,1,1,1]) should return true allequal ([1,1,2,1]) should return false

COMP 2406: Fundamentals of Web Applications. Fall 2013 Mid-Term Exam Solutions

Enterprise Web Development

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

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to the World Wide Web (cont d.) Introduction to the World Wide Web

DLint: Dynamically Checking Bad Coding Practices in JavaScript

Static Analysis for JavaScript

Don't Call Us, We'll Call You:

The Discussion of Cross-platform Mobile Application Development Based on Phone Gap Method Limei Cui

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

TypeScript coding JavaScript without the pain

A Structural Operational Semantics for JavaScript

JavaScript Specialist v2.0 Exam 1D0-735

JavaScript Patterns O'REILLY* S toy an Stefanov. Sebastopol. Cambridge. Tokyo. Beijing. Farnham K8ln

COMS 469: Interactive Media II

COMS 469: Interactive Media II

NODE.JS MOCK TEST NODE.JS MOCK TEST I

Notes on JavaScript (aka ECMAScript) and the DOM

JavaScript or: HOW I LEARNED TO STOP WORRYING AND LOVE A CLASSLESS*

React(.js) the Domino Way High-Performance Client for Domino. Knut Herrmann

JavaScript: More Syntax

JavaScript for PHP Developers

Session 16. JavaScript Part 1. Reading

There are two main workflows for working with Cordova projects, Web focused and Platform focused.

CS 130(0) JavaScript Lab

Kyle Rainville Littleton Coin Company

Pace University. Fundamental Concepts of CS121 1

Short Notes of CS201

Experimental New Directions for JavaScript

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

ADsafety. Type-based Verification of JavaScript Sandboxing. Joe Gibbs Politz Spiridon Aristides Eliopoulos Arjun Guha Shriram Krishnamurthi

Modern Web Application Development. Sam Hogarth

CS201 - Introduction to Programming Glossary By

Java vs JavaScript. For Enterprise Web Applications. Chris Bailey IBM Runtime Technologies IBM Corporation

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Transcription:

INF5750 Introduction to JavaScript and Node.js

Outline Introduction to JavaScript Language basics Introduction to Node.js Tips and tools for working with JS and Node.js

What is JavaScript? Built as scripting language for adding dynamic features to Web pages Originally developed for Netscape Navigator in 1995 Reverse engineered by MS in 1996 for IE as JScript Submitted to ECMA for standardisation - first language standard released in 1997 as ECMA-262 (ECMAScript) ECMAScript is the specification - JavaScript is an Oracle trademark

How is JS used? Client-side (e.g. browser) Scripting language for web pages 94,7% of web sites use JS (w3techs.com) Server-side (e.g. node.js) Fastest growing (but still tiny) server-side language for web sites Other: Browser extensions, mobile apps (Cordova), scripting applications (Adobe CS, OpenOffice++)

JavaScript Engines Support for (new) language features varies slightly Multiple javascript engines/interpreters exists: V8 (Chrome and Node.js) Chakra (Edge) SpiderMonkey (Firefox) JavaScriptCore (Safari) +++

Key Features High-level Weakly typed Object-oriented Interpreted

High level High level of abstraction from the hardware No need to deal with memory etc Easier to develop and use across different platforms

Weakly typed Variable types are derived from the values they are assigned No type safety or type checking Built-in types still exist («String», «Number» etc)

Object oriented JS is object oriented, but prototype-based - no real class concept with inheritance etc All objects inherit from a prototype object More later (and next week)

Interpreted Not pre-compiled to byte or machine code Code is interpreted and executed by the JS engine at runtime

Java and Javascript are similar like Car and Carpet are similar Chris Heilmann

Basic language constructs Values and types Conditionals Functions Variables Prototypes [more next week]

Values and types JS uses weak/dynamic typing - flexible, but potentially more error-prone A variable can hold values of different types

Values and types Built-in types: boolean number string null and undefined object symbol Built-in types have properties and methods, e.g "hello world».toupper()

Values and types The object type represent compound values var anobject = { firstname: "John", lastname: "Doe" } Arrays and functions are special forms of objects

Values and types Comparing different value types requires type conversion: implicit conversion (coercion) explicit conversion false values in JS: "", 0, -1, NaN, null, undefined false operators: equality with coercion allowed: ==,!= equality without coercion: ===,!==

Conditionals If else if if Switches Conditional operator: [condition]? [if true] : [if false]

Functions Defines a scope (more in a minute) Functions as named variables var adder = function(a, b) { return a + b; } adder(1, 2); //= 3 Immediately invoked function expressions (function example() { console.log("test"); }()

Functions var a = "global scope"; scope1(); function scope1() { var b = "scope of scope1()"; function scope2() { var c = "scope of scope2()"; } } console.log(c); //ReferenceError

Variables Variables and object properties must be valid identifiers (a-z, A-Z, 0-9, $, _) Declared variables belong to a function scope or global scope Scopes can be nested - variables are available to inner scopes Variable and function declarations are hoisted

Prototypes JS is object oriented, but does not have classes* - uses Property-based inheritance Every JS object has a property [[Prototype]] referencing it s prototype Prototype chain: when trying to access a property of an object, that property will also be searched in all consecutive prototypes of the object * ES2015 introduces class, but only as syntic sugar

Asynchronous programming JS is single-threaded - I/O is asynchronous Requirement that web pages are not blocked e.g. while waiting for data to be returned over the network Rely on callbacks, promises, events More next week

What is Node.js? Node.js is a JS runtime for running JS code server-side Based on V8 engine from Chrome Basic libraries included in Node.js itself npm package manager with 400 000+ libraries and frameworks

What is Node.js Most common use for node.js is development of web services Also be used for general scripting etc Demos: "Hello World" Using a library from npm

Node.js HTTP server Node.js comes with http library for http communication Example - receiving requests Frameworks would normally be used to abstract away details of e.g. the http library

Useful hints/tools CURL/Postman for HTTP requests Debugging node.js with Chrome Using "strict mode" Using a code checker like jshint, eslint, etc

CURL/Postman CURL - https://github.com/curl/curl Command line tool for making HTTP requests Use verbose mode to see details (-v or -vv) Postman - https://www.getpostman.com/ Available as chrome extension, app etc GUI tool for interacting with API

Debugging node.js Chrome can be used for debugging node.js: 1. Run node with "-- inspect" argument 2. Open chrome://inspect in Chrome 3. Select "Open dedicated DevTools for node.js"

strict mode Enabled by adding "use strict;" to your.js file Strict mode disallows "bad" or "uncertain" behaviour

Code checker Different code checkers available to check code quality Useful to make sure your code is consistent Examples: JSlint, JSHint, ESlint

Obligatory assignment 1 http://www.uio.no/studier/emner/matnat/ifi/inf5750/h17/ Assignments/inf5750_assignment1.html