JavaScript: The Basics

Similar documents
JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications

Chapter 3 Data Types and Variables

CSC Web Programming. Introduction to JavaScript

Client-Side Web Technologies. JavaScript Part I

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

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

Working with JavaScript

CGS 3066: Spring 2015 JavaScript Reference

JavaScript: More Syntax

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

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

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

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

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

JavaScript: Introduction, Types

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

JavaScript Basics. The Big Picture

Such JavaScript Very Wow

HTML5 and CSS3 More JavaScript Page 1

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


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

Tutorial 10: Programming with JavaScript

JavaScript by Vetri. Creating a Programmable Web Page

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

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

COMS 469: Interactive Media II

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

JavaScript I Language Basics

Exercise 1: Basic HTML and JavaScript

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

Like most objects, String objects need to be created before they can be used. To create a String object, we can write

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

UNIT-4 JAVASCRIPT. Prequisite HTML/XHTML. Origins

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 BASICS. Type-Conversion in JavaScript. Type conversion or typecasting is one of the very important concept in

<script type="text/javascript"> script commands </script>

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

Princess Nourah bint Abdulrahman University. Computer Sciences Department

PHP by Pearson Education, Inc. All Rights Reserved.

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

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

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

JavaScript: Introductionto Scripting

INF5750. Introduction to JavaScript and Node.js

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

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

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

Programming language components

CHAPTER 6 JAVASCRIPT PART 1

Server side basics CS380

Web Site Design and Development JavaScript

CSCE 120: Learning To Code

The JavaScript Language

PHP. Interactive Web Systems

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

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

write vs. writeln Prompting as Page Loads Today s Goals CSCI 2910 Client/Server-Side Programming Intermediate File vs. HTML Output

CHIL CSS HTML Integrated Language

Chapter 4 Basics of JavaScript

JavaScript: Introduction to Scripting

EXERCISE: Introduction to client side JavaScript

CS312: Programming Languages. Lecture 21: JavaScript

JavaScript Introduction

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

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

JavaScript. What s wrong with JavaScript?

JavaScript Lecture 1

Language Reference Manual

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Primitive Data Types: Intro

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

Client vs Server Scripting

Introduction to Computer Science and Object-Oriented Programming

c122mar413.notebook March 06, 2013

Program Design Phase. Algorithm Design - Mathematical. Algorithm Design - Sequence. Verify Algorithm Y = MX + B

JavaScript: More Syntax and Using Events

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

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

The PCAT Programming Language Reference Manual

COMS 469: Interactive Media II

Decaf Language Reference Manual

1/11/2010 Topic 2: Introduction to Programming 1 1

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

Programming Basics. INFO/CSE 100, Spring 2005 Fluency in Information Technology.

Programming Basics. Part 1, episode 1, chapter 1, passage 1

Program Fundamentals

introjs.notebook March 02, 2014

CIW 1D CIW JavaScript Specialist.

CS112 Lecture: Primitive Types, Operators, Strings

CS1520 Recitation Week 2

Topic 2: Introduction to Programming

COSC 122 Computer Fluency. Programming Basics. Dr. Ramon Lawrence University of British Columbia Okanagan

Pace University. Fundamental Concepts of CS121 1

Typescript on LLVM Language Reference Manual

Transcription:

JavaScript: The Basics CISC 282 October 4, 2017 JavaScript A programming language "Lightweight" and versatile Not universally respected Appreciated in the web domain Adds programmatic functionality to webpages Dynamically alters the page Handles interaction with the user e.g., responds to events, validates input Not really related to Java Somewhat similar syntax JavaScript is much more relaxed 2

JavaScript Implements the ECMAScript standard Produced by the ECMA An "industry association" Develops standards such as "Office Open XML Formats" Created at Netscape IE's version was called JScript until recently Some minor browser variations Runs client-side in the browser Loaded with the webpage Along with HTML and CSS No other communication required with the server 3 JavaScript Near-universally supported version: 5 th edition Finalized in 2009 Currently widely supported version: 6 th edition Otherwise known as ECMAScript 2015 Not supported in IE10; imperfect support in IE11 Improvements: Constants Variables with block scope Default values for function parameters Object-oriented class definitions and more We ll focus on the 5 th with a little from the 6 th 4

Java vs. JavaScript Aspect Java JavaScript Type Compiled Interpreted Variables Typed Untyped Declared Declared or undeclared Errors Exceptions Generally ignored Design Focus Objects Functions 5 Linking to HTML Explicit embedding JavaScript code lives in the HTML file Problematic Does not separate content and behaviour Can cause XHTML validation errors Can't be used in multiple files Implicit embedding JavaScript code lives in a separate file Linked to HTML file using <script> tag <script src= path ></script> Include type= text/javascript for XHTML 6

Fundamental Types Type String Examples "in double quotes", 'in single quotes', Number 12, 2.15, 0.3,... Boolean Array true, false [ 1, 3, 5, 7, 11, 13], function function helloworld() {...} null undefined null undefined 7 Number Represents both reals and integers Basic operators +,, *, / and % Division may produce a real e.g., 10 / 4 = 2.5 Expressions evaluated in a typical manner Brackets first, etc. Operators with assignment ++,, +=, =, *= and /= 8

Number Constants Number.MIN_VALUE and Number.MAX_VALUE Smallest and largest values permitted Number.NEGATIVE_INFINITY Number.POSITIVE_INFINITY Also known as Infinity Number.NaN "Not a number" Result of an invalid expression e.g., 10 / "Hello world!" NaN 9 Math Global object provided by Javascript Offers useful properties & functions e.g., Math.PI Function Math.min(x,y) Math.max(x,y) Return Value The minimum/maximum of the two parameters Math.random() A random-ish value in [0,1) Math.floor(x) Math.ceil(x) The integer resulting from rounding down/up 10

Variables Loosely typed Can store values of any variety (unlike Java) Declaration is not necessary...... but it is highly recommended May cause problems if you don't Can use var or let More on these later Names must begin with a letter or underscore Names may also include digits 11 Strings Can enclose in double quotes "like this" Use \" for the double-quote character Can enclose in single quotes 'like this' Use \' for the apostrophe character Other special characters Backslash: \\ Newline: \n Tab: \t There is no Character type in JavaScript Even a single character is a String Individual characters are indexed from 0 12

Strings Concatenate with the + operator Not the same as addition for numbers Converts other types into Strings as needed e.g., 2 + 4 + " is the answer" "6 is the answer" parseint(...) and parsefloat(...) convert Strings to Numbers Return NaN if parameter is invalid Each String has a.length property Much like arrays in Java e.g., "hello".length 5 13 Some String Functions Function charat(anindex) indexof(astring) substring(start,end) tolowercase() touppercase() Return Value Individual character at the given index Index of first occurrence of astring; -1 if non present Characters between the given indices Copy of the string with all lower/uppercase letters 14

For Loops for(initialvalue; condition; operation) {... } Can declare a variable in initialvalue or not for(var i = 10; i > 0; i ) {... } or var i = 1; for(i = 10; i > 0; i ) {... } 15