Introduction to JavaScript

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
Chapter 17 Fundamental Concepts Expressed in JavaScript.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fundamental Concepts Expressed in JavaScript Get with the Program lawrence.
JavaScript, Fourth Edition
Guide To UNIX Using Linux Third Edition
JavaScript, Third Edition
Chapter 17 Fundamental Concepts Expressed in JavaScript.
The Information School of the University of Washington Oct 20fit programming1 Programming Basics INFO/CSE 100, Fall 2006 Fluency in Information Technology.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
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.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
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.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
REEM ALMOTIRI Information Technology Department Majmaah University.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
Web Database Programming Using PHP
>> Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
“Under the hood”: Angry Birds Maze
Tutorial 10 Programming with JavaScript
JavaScript is a programming language designed for Web pages.
Fluency with Information Technology
Web Database Programming Using PHP
Overview: Programming Concepts
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
Highly Engaging and Dynamic Data-driven Visualization with Javascript
JavaScript an introduction.
Chapter 17 JavaScript.
Chapter 8 JavaScript: Control Statements, Part 2
WEB PROGRAMMING JavaScript.
JavaScript: How To? B. Ramamurthy.
Introduction to JavaScript
Introduction to JavaScript
INFO/CSE 100, Spring 2005 Fluency in Information Technology
T. Jumana Abu Shmais – AOU - Riyadh
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Web DB Programming: PHP
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
Javascript Chapter 19 and 20 5/3/2019.
More JavaScript B. Ramamurthy 5/7/2019.
Introduction to JavaScript
CIS 136 Building Mobile Apps
Programming Basics Review
Chapter 8 JavaScript: Control Statements, Part 2
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Introduction to JavaScript B. Ramamurthy 12/1/2018

Overview We will begin with simple exercises on HTML (UI)+JS (control/action)+CSS (style) We will focus on separation of the various components. Then we will drop the style (css) and focus on a few popular js libraries/frameworks such as jquery and angularjs (later) 12/1/2018

Structure – Style -- Interaction HTML provides structure CSS provides style; CSS provides style attributes for the HTML selector tags Javascript (JS) provides control for interaction and operations JS provides functions that can be called to perform operations 12/1/2018

Exercise with all three components <!DOCTYPE html> <head> <title> My first JavaScript </title> <style> h1{color: blue} </style> </head> <body> <h1> <script> document.write("Hello World!") </script> </h1> </body> </html> Head Style/css Body Script/js 12/1/2018

Separate files for style and scripts <!DOCTYPE html> <head> <title> My first JavaScript </title> </head> <body> <h1> js function outside </h1> </body> </html> Head .css file <style> h1{color: blue} </style> Style/css Body <script src="myscripts.js"></script> .js file function mywrite() {document.write("Hello World!");} 12/1/2018

Moving CSS, JS to an external files We can separate style elements in css file, behavioral elements can be moved to an external js file. This separation of concerns has resulted in explosion of javascript libraries (framework) and css style libraries. Large collection of superior and highly useful js libraries are available 12/1/2018

JS functions Javascript “script” consists of functions. A function consists of function followed by the name of the function The statement that make up the function go next within curly brackets Example: function saySomething() { alert(“ We are learning basics of JS”); } 12/1/2018

Putting all together .html file .css file application Web browser Javascript Libraries .html file .css file application Web browser Firefox/ Safari image and audio files .js file interprets displays Style(.css) Libraries Prepare/edit files 12/1/2018

Visualizations Great visualizations are not just informative but initiate conversations, explosion of free social media communications/messaging/instagramming etc. result in valuable free marketing to target customer segment Great visualization tells a story instantly Excel is de facto standard but it is designed as a data entry application and optimized for graphs/plots: not good for unstructured and social media data; look beyond excel tables and graphs Interactive visualization provides new modes of engagement previously impossible Opens up previously invisible aspects of data 12/1/2018

HTML5+DOM No matter what the backend, HTML and JavaScript are the technologies for all web developers for front end. 12/1/2018

Programming Concepts This chapter introduces the following programming concepts: Names, values, and variables Declarations Data types, numbers, string literals, and Booleans Assignment Expressions Conditionals

Identifiers and Their Rules The letter sequence that makes up a variable’s name is called the identifier Identifiers have a particular form Identifiers must begin with a letter, followed by any sequence of letters, numerals, or the underscore symbol Identifiers are not allowed to contain spaces

Identifiers and Their Rules Note two features of identifiers: The underscore symbol can be used as a word separator It makes identifiers more readable There is a “no spaces” rule Identifiers are case sensitive uppercase and lowercase letters are different

Variable Declaration Statement var area, radius; This command declares that two identifiers (area, radius) will be used as variables

Rules for Declaring Variables Every variable used must be declared JavaScript allows declaration statements anywhere in the list of statements Variable declarations announce what variables will be used in the program Declare variables first

Initializing a Declaration Sometimes there is an initial value for identifiers JavaScript allows setting the initial value as part of the declaration This is called initializing the variable Declaring variables with initial values is written as: var taxRate = .088; var balanceDue = 0;

Strings Strings are a common kind of data Strings are “sequences of keyboard characters” Notice that a string is always surrounded by single (') or double (") quotes Strings can initialize a declaration Strings are needed when manipulating text

Rules for Writing Strings in JavaScript There are rules for writing strings in JavaScript: Strings must be surrounded by quotes, either single (') or double ("), which are not curly Most characters are allowed within quotes except: the return character ( ), backspace character, tab character, \, and two little used others Double quoted strings can contain single quotes, and vice versa

Rules for Writing Strings in JavaScript There are rules for writing strings in JavaScript: The apostrophe (') is the same as the single quote Any number of characters is allowed in a string. The minimum number of characters in a string is zero (""), which is called the empty string

Strings To use double quotes in a string, enclose the string in single quotes: var answer = 'He said, "No!“ ‘ If our string contains single quotes, enclose it in double quotes: var book = "Guide to B&B's" Since the apostrophe is commonly used in possessives and contractions, use double quotes as the default

Escape Mechanisms For JavaScript, the escape symbol is the backslash (\) The escape sequences are converted to the single characters they represent when stored in the computer’s memory

Boolean Values Another kind of value is the Boolean value (Booleans) There are only two Boolean values: true and false Boolean values are written as letter sequences, they are values, not identifiers or strings Booleans are used implicitly throughout the programming process

Relational Operators Relational operators make comparisons between numerical values The relationship between two numbers is tested The outcome of the comparison is a Boolean value of true or false The “equal to” relational operator (==) is a double equal sign The “not equal to” operator uses the !

Operator Overload Operator overload is a technical term meaning the “use of an operator with different data types” Strings to numbers or to Booleans Operators usually apply to a single data type 4 + 5 produces the numerical result of 9 If operands are strings, what does the + mean?

Concatenation When we use + with strings, it joins the strings by the operation of concatenation It just means that the two strings are placed together if we want them joined The meaning of + is overloaded: + to mean addition when operands are numeric + means concatenation when the operands are strings

if Statements and Their Flow of Control if (waterTemp < 32) waterState = "Frozen"; The <Boolean expression> is called a predicate It is evaluated, resulting in a true or false outcome If the outcome is true, the <then-statement> is performed If the outcome is false, the <then-statement> is skipped

if/else Statements if (<Boolean expression>) The if/else statement contain statements that will be executed when the condition’s outcome is false if (<Boolean expression>) <then-statement>; else <else-statement>;

Summary We looked at basic elements of JavaScript language. These were introduced to illustrate the common constructs that JS has with many of the high level languages that you are familiar with. 12/1/2018