CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

Java Script Session1 INTRODUCTION.
The Web Warrior Guide to Web Design Technologies
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
1 JavaScript
JavaScript Syntax, how to use it in a HTML document
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 JavaScript in Context. Server-Side Programming.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
CGS 3066: Web Programming and Design Spring 2017
>> Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Intro to JavaScript CS 1150 Spring 2017.
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript an introduction.
WEB PROGRAMMING JavaScript.
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
JavaScript: Introduction to Scripting
CGS 3066: Web Programming and Design Fall 2019
Presentation transcript:

CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript

What is JavaScript? A programming language that can be executed in every modern browser. “Interpreted” language – Do not need to be compiled before execution. – Must be executed by an interpreter. Browsers come with their own JavaScript Engine (e.g. V8 in Chrome, Gecko in Mozilla) Written in scripts, executed at the client side(browser) – To interact with the user locally – No need to refresh the page, less traffic for server

Are Javascript and Java Similar? ● No! ● Java is a full-fledged object-oriented programming language, popular for developing large-scale enterprise applications and web applications ● Javascript is meant for use in Web programming only ● No File I/O capability, networking functions ● Targeted for HTML authors ● Faster alternative to Java in web applications

What can we do with JavaScript? A lot Most common uses include – Interaction with user through pop-up boxes – Access any element in the document and manipulate its look, content and attributes – Create new elements and content and apply them to the document when and if they are needed – Event handling: execute operations when certain events are detected(button clicked, key pressed, mouse hovered, page loaded, value of some HTML element changed, or simply at specific time interval)

Javascript usage examples Form validation Survey/Questionnaire design with dynamic contents Draw and animate graphic elements Create User interface widgets(e.g. Search box with autocomplete, draggable and resizable objects)

How to use JavaScript JavaScript code can be inserted into a HTML file. – In both and For example JS Hello World window.alert("Hello World"); * The type attribute ("text/javascript“) is required for HTML4, optional for HTML5

JavaScript code in HTML must be inside the tag. JavaScript can be also included from external sources using tag. Just put the following into or tag async tells the browser to load script from source asynchronously (in parallel with loading HTML content ) defer tells the browser to load script after the entire HTML document is loaded How to use JavaScript

JavaScript Syntax JavaScript’s basic syntax is identical to that of C++ and Java. // begins a comment that ends at the end of the line /* and */ may be used to contain multiline comments For instance //This is Inline comment /*Multi- line comment*/ tags typically contain one or several Javascript ‘statements’ statements must be separated by new lines or the semicolon(;) character

JavaScript Variables Named variables are used to store data values. The “ var ” keyword is used to declare variables. “=” is used to set values to variables. Example: var length; length = 6; Variables may be declared and defined in a single statement: var length=6; Unlike HTML, Javascript variables are case-sensitive

JavaScript does not have typed variables. – The variable declarations do not specify a data type for the variables – May be used to associate values of any type to a variable – E.g. Integer: var num1 = 10; Floating point numbers: var PI = ; Alphabetic Character: var color = ‘c’; String of Characters: var firstname = “David”// ‘David’ also works Booleans : var x= true; var y= false; Empty/null value: var x=null; //not NULL or Null;case-sensitive Or, Arrays,Objects etc. JavaScript Variables

JavaScript has dynamic types. A Variable having value of a certain may be re-assigned to contain another data type var x; //no data type var x = 5; //it is a number x = “Steven” //change to a string You can use the JavaScript typeof operator to find the current data type of a JavaScript variable. window.alert(typeof "John"); //prints “string” JavaScript Variables

JavaScript Operators ● Arithmetic: +, -, *, /, %, ++, -- ● Assignment: =, +=, -=, *=, /=, %= etc. ● Relational/Comparison:, =, ==,===, != ● Logical: &&, ||, !

JavaScript String Concatenation operator ● The (+) operator is used to concatenate/join the operands when at least one operand is of String type var x=“Foo”+”bar” //x becomes ”Foobar” var y=“ben”+10 //y becomes ”ben10” (+=) may also be used for concatenation, depending on the context var x=5; x+=5;//x is 10 var y=“5” y+=5//y is “55” x+=y //x is “1055”

Javascript Input/Output capabilities Javascript can perform limited Input/output through pop-up boxes To generate a pop-up box: window.alert("Hello\nworld!"); Use ‘\n’ to enter new line inside pop-up message To read input from pop-up: var name= window.prompt(“Enter your name”); * alert() and prompt() also works even if not preceded by “window.”

Javascript Input/Output capabilities(2) To print some content directly to the web page, use document.write() function: document.write(“plain HTML content"); document.write(" we can also write Content with HTML tags "); document.writeln() automatically adds a line at the end of string document.writeln(“HTML content with newline");

Javascript Input/Output capabilities(3) Most current browsers provide access to the browser's debugging console. Although a non-standard feature, the console is frequently used be developers to print and inspect data in bulk To access the console output, press F12 and click on ‘console’ To print message to the console, use the console.log() function console.log(" press f12 or right click to Inspect Element. \n Then click Console to find this message!");