Such JavaScript Very Wow

Similar documents
CSC Web Programming. Introduction to JavaScript

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

COMS 469: Interactive Media II

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

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

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

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

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

JavaScript CS 4640 Programming Languages for Web Applications

The Number object. to set specific number types (like integer, short, In JavaScript all numbers are 64bit floating point

CITS1231 Web Technologies. JavaScript Math, String, Array, Number, Debugging

JavaScript CS 4640 Programming Languages for Web Applications

Client-Side Web Technologies. JavaScript Part I

Chapter 2 Working with Data Types and Operators

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

1001ICT Introduction To Programming Lecture Notes

HTML5 and CSS3 More JavaScript Page 1

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

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

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

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

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

CGS 3066: Spring 2015 JavaScript Reference

JavaScript Introduction

Java Basic Datatypees

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

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

CECS 189D EXAMINATION #1

JavaScript Basics. The Big Picture

JavaScript: The Basics

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Coding in JavaScript functions

Pace University. Fundamental Concepts of CS121 1

CS112 Lecture: Primitive Types, Operators, Strings

What did we talk about last time? Examples switch statements

Javascript Methods. concat Method (Array) concat Method (String) charat Method (String)

2 nd Week Lecture Notes

Language Reference Manual

Built-in Types of Data

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

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

JavaScript Functions, Objects and Array

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

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

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

The Very Basics of the R Interpreter

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

Scheme Quick Reference

COMS 469: Interactive Media II

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

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

Basic types and definitions. Chapter 3 of Thompson

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Chapter 3 Data Types and Variables

Chapter 17. Fundamental Concepts Expressed in JavaScript

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

Full file at

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

Introduction to Computer Science and Object-Oriented Programming

DC71 INTERNET APPLICATIONS JUNE 2013

Fundamentals of Website Development

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:

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 2

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Scheme Quick Reference

A variable is a name for a location in memory A variable must be declared

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

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

Language Reference Manual simplicity

We now start exploring some key elements of the Java programming language and ways of performing I/O

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

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Introduction to Web Tech and Programming

Full file at Tutorial 2: Working with Operators and Expressions

CISC 110 Week 3. Expressions, Statements, Programming Style, and Test Review

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

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

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

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

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Introduction to C Language

The SPL Programming Language Reference Manual

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

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

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

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

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

VARIABLES AND TYPES CITS1001

FORMULAS QUICK REFERENCE

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

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

JavaScript I Language Basics

TCL - STRINGS. Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.

COMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts


HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

Transcription:

Such JavaScript Very Wow Lecture 9 CGS 3066 Fall 2016 October 20, 2016

JavaScript Numbers JavaScript numbers can be written with, or without decimals. Extra large or extra small numbers can be written with scientific (exponent) notation. All numbers are 64-bit floating point. Integers can have up to 15 digits. Floats can have up to 17 decimal digits. JavaScript interprets numeric constants as hexadecimal if they are preceded by 0x. If you want numbers printed in different bases, use the tostring function.

JavaScript Number Class functions These are some of the functions available under the Number class, that works on all numbers. tostring() returns a number as a string. toexponential() returns a string, with a number rounded and written using exponential notation. tofixed() returns a string, with the number written with a specified number of decimals. toprecision() returns a string, with a number written with a specified length. valueof() returns a number as a number. parseint() parses a string and returns a whole number. Spaces are allowed. Only the first number is returned. parsefloat() parses a string and returns a number. Spaces are allowed. Only the first number is returned.

JavaScript Math Object The JavaScript Math object allows you to perform mathematical tasks on numbers. Math.round(x) returns the value of x rounded to its nearest integer. Math.pow(x,y) returns the value of x to the power of y. Math.sqrt(x) returns the square root of x Math.abs(x) returns the absolute (positive) value of x Math.random() returns a random number between 0 (inclusive), and 1 (exclusive. The Math Class has many properties like PI, E, SQRT2, LOG2E, etc. The Math class also has many other functions like sin, cos, tan, floor, ceil, log, exp, etc

Strings JavaScript strings are used for storing and manipulating text. Adding a backslash in fromt of a character is called escaping the character. There are several special escaped characters in JavaScript. \ - single quote \ - double quote \\- backslash \n - newline \t - tab \b - backspace

String Functions The length property returns the length of a string. The indexof() method returns the index of (the position of) the first occurrence of a specified text in a string The search() method searches a string for a specified value and returns the position of the match. slice() extracts a part of a string and returns the extracted part in a new string. The replace() method replaces a specified value with another value in a string. concat() joins two or more strings. The charat() method returns the character at a specified index (position) in a string. There are many more methods.

Objects An object is a software representation of a real world entity. Objects have properties (whose values identify an object) and methods that act on those properties. JavaScript variables are containers for data values. The values are written as name:value pairs (name and value separated by a colon). var car = {make:"toyota", model:"corolla", color:"silver", year:2009};

Object Methods JavaScript methods are the actions that can be performed on objects. A JavaScript method is a property containing a function definition. Methods can be built-in (already available in JavaScript) or user defined. You create an object method with methodname : function() { code lines } You access an object method with objectname.methodname()

Declaring Objects With JavaScript, you can define and create your own objects. There are different ways to create new objects: Define and create a single object, using an object literal. Define and create a single object, with the keyword new. Define an object constructor, and then create objects of the constructed type.

Everythings an object

Everything s an object In JavaScript, almost everything is an object. Booleans, Numbers and Strings can be objects (or primitive data treated as objects). Dates, Maths, Regular Expressions, Arrays, and Functions are always objects. Objects are objects. In JavaScript, all values, except primitive values, are objects. Primitive values are: strings, numbers, true, false, null, and undefined.

The this keyword In JavaScript, the thing called this, is the object that owns the JavaScript code. The value of this, when used in a function, is the object that owns the function. The value of this, when used in an object, is the object itself. The this keyword in an object constructor does not have a value. It is only a substitute for the new object. The value of this will become the new object when the constructor is used to create an object.

Scope Scope refers to the set of variables, objects, and functions you have access to. JavaScript has function scope: the scope changes inside functions. Variables can be local or global. The lifetime of a JavaScript variable starts when it is declared. Local variables are deleted when the function is completed. Global variables are deleted when you close (or move away from) the page.

Local varibales Variables declared within a JavaScript function, become local to the function. Local variables have local scope: They can only be accessed within the function. Since local variables are only recognized inside their functions, variables with the same name can be used in different functions. Local variables are created when a function starts, and deleted when the function is completed.

Global Variables A variable declared outside a function, becomes global. A global variable has global scope: All scripts and functions on a web page can access it. If you assign a value to a variable that has not been declared, it will automatically become a global variable. With JavaScript, the global scope is the complete JavaScript environment. In HTML, the global scope is the window object: All global variables belong to the window object.

Events HTML events are things that happen to HTML elements. For example, an HTML button click, a page finishing up loading, a key press, etc. are all events. JavaScript lets you execute code when events are detected. HTML allows event handler attributes, with JavaScript code, to be added to HTML elements. Event handlers can be used to handle, and verify, user input, user actions, and browser actions. Syntax: <some-html-element some-event= some JavaScript >

Some Common Events Event onclick onload onchange onkeydown onmouseover ondrag onselect onsubmit Description The user clicks an HTML element The browser has finished loading the page An HTML element has been changed The user pushes a keyboard key The user moves the mouse over an HTML element The event occurs when an element is being dragged The event occurs after the user selects some text The event occurs when a form is submitted

Form submission The action attribute holds the URL for the action script that has to be executed when the form is submitted. The action script can be a PHP, a JSP, an ASP, or anything of the sort. The action script can also be another HTML file. When the form is submitted, all the user entered data is sent to the server. Data is sent in as field-value pairs. Visibility of the data depends on the method of submission: get or post.

get and post methods get All form data is visible in the URL The size of appended data is restricted. Very insecure. Used primarily while testing. post Form data is not in the URL. Protected during transmission. Size of data is potentially unlimited. Quite secure. Preferred by programmers.

Form Validation Data validation is the process of ensuring that computer input is clean, correct, and useful. Typical validation tasks are: has the user filled in all required fields? has the user entered a valid date? has the user entered text in a numeric field? Validation can be defined by many different methods, and deployed in many different ways.