Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.

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

1 COMM 1213 H1 COMP 4923 X1 JavaScript 1 (Readings: Ch. 10, 11 Knuckles)
Types and Arithmetic Operators
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Tutorial 10 Programming with JavaScript
Python November 14, Unit 7. Python Hello world, in class.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
JavaScript, Third Edition
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Introduction to scripting
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
Computers and Scientific Thinking David Reed, Creighton University JavaScript and User Interaction 1.
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. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 5 JavaScript.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
JavaScript, Fourth Edition
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
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 Server versus Client-Side Programming Server-SideClient-Side.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
1 JavaScript in Context. Server-Side Programming.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
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.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Expressions and Data Types Professor Robin Burke.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
>> Introduction to JavaScript
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
BASIC ELEMENTS OF A COMPUTER PROGRAM
Scope, Objects, Strings, Numbers
JavaScript.
JavaScript an introduction.
Introduction to C++ Programming
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript What is JavaScript? What can JavaScript do?
Tutorial 10 Programming with JavaScript
JavaScript What is JavaScript? What can JavaScript do?
Unit 3: Variables in Java
Presentation transcript:

Javascript II Expressions and Data Types

2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element programs consist of statements executed sequentially

3 Statements End with semi-colon Cannot occupy multiple lines Assignment statement var = value; The “value” on the right can be any legal expression Function call document.write ("foo");

4 Variables A variable is a named location where a value can be stored In JavaScript using a variable creates it can also declare Other languages require that variables be declared before being used Variables have "scope" locations in the program where they are valid will discuss this later on

5 Variable declaration Declaration is optional in Javascript Syntax var foo; Says that foo is a variable we will use later

6 Data types What is the difference between the following statements val1 = "53"; val2 = 53; These values are different to JavaScript stored differently manipulated differently same operation may mean something different + on strings in concatenation + on numbers is addition

7 Data Type A characterization of a stored value Determines what kinds of values can be stored how the value is stored internally what operations can be applied Syntactic representation how the value is expressed in a program

8 JavaScript Types Strings Integers Floats real numbers Boolean true or false

9 Strings What values lists of characters any length including the zero-length “null” string “” What operations concatenation (+ operator) output to the Web page using document.write(…) returned by prompt() function Syntax double or single quotes

10 Examples val1 = “Hello"; val2 = ‘ there'; val3 = val1 + val2; document.write (val3); val4 = “45”; val2 = val3 + val5; document.write (val2);

11 Integers What values whole numbers between and What operations standard mathematical operations (+, -, *, /) special math functions Syntax unquoted integers Note book doesn't use integers in examples

12 Examples val1 = 45; val2 = 055; val3 = val1 + val2; Math.sqrt(val3);

13 Float What values decimal values from ±1.0x to ± 1.0x digits of precision (past decimal point) What operations standard mathematical operations special math functions Syntax unquoted decimal values scientific notation 1.2e3 = 1.2 x 10 3 = 1200

14 Examples val1 = 5.3; val2 = 5.3e1; val3 = val1 + val2; Math.floor(val3);

15 Boolean What values true / false What operations logical operations and && or || not ! Syntax keywords (true, false)

16 Examples val1 = true; val2 = false; val3 = val1 && !val2;

17 Another kind of value var foo; document.write (foo); What is the value of foo?

18 undefined value This is the value of a variable when it is created if you use a variable without defining it, you get an error You can declare a variable without giving it a value not an error variable has no value unexpected results

19 Expressions An expression is a legal combination of Javascript values, operators, function calls and variables that evaluates to a value Examples a + b 5 / * r * r Math.sqrt (errorTerm) "foo" + "-" + "bar"

20 Syntax alert An expression is not a statement an expression may be part of a statement note: no semi-colon Example (a + b) / 2 expression size = a + b; statement

21 Evaluation An expression is evaluated when it is executed (run-time) Steps Each variable is replaced by its current value Operators are applied Until a single value remains

22 Example a = 5; b = 20; position = (a * 5) + (b / 10);

23 Complex expression Expressions can be large and complex JavaScript doesn't care Readers of your program might care A complex expression can always be simplified by using intermediate variables

24 Example complex expression slope = ( (y1 – y2) / (x1 – x2) ); simplified deltaY = y1 – y2; deltaX = x1 – x2; slope = deltaY / deltaX;

25 The "+" trap + means different things for different types "foo" + "bar"  "foobar" "5" + "6"  "56"  11 What about? "5" "foo"

26 Operators + is an operator An operator takes two values (sometimes one) makes ("returns") a new value Some operators are two characters && Assignment is not an operation = is not an operator!

27 Functions Like an operator takes values does some operation returns a result But has a name instead of symbol can take any number of values can be user-defined

28 Predefined Functions You can define your own functions later in the class Many built-in prompt document.write

29 Function syntax prompt ( "Enter a number", "0") return value is a string containing the user input No parameters? Math.random () there's still a list, just an empty one function nameparameter #1 parameter #2 parameter list