Javascript. Javascript Tools Javascript Console Javascript Console Debugger Debugger DOM Inspector DOM Inspector.

Slides:



Advertisements
Similar presentations
Data Types and Operators Using Data Types
Advertisements

1 COMM 1213 H1 COMP 4923 X1 JavaScript 1 (Readings: Ch. 10, 11 Knuckles)
Operators and Expressions Operators are symbols that produce a result based on some rules. Examples: +, -, =, > and
Lesson 4: Formatting Input Data for Arithmetic
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Python November 14, Unit 7. Python Hello world, in class.
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.
JavaScript, Third Edition
Printing. printf: formatted printing So far we have just been copying stuff from standard-in, files, pipes, etc to the screen or another file. Say I have.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Introduction to scripting
Working with Numbers parseInt() and parseFloat() Math.round() Other Math object functions isNaN() toFixed()
Homework Reading Programming Assignments
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
JavaScript Part 2 – Page 1 of 35CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: JavaScript Part 2.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Data Types.
Chapter 3 : Processing on the Front End JavaScript Technically its name is ECMA-262, which refers to the international standard which defines it. The standard.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Data types, Literals (constants) and Variables Data types specify what kind of data, such as numbers and characters, can be stored and manipulated within.
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
SE-2840 Dr. Mark L. Hornick 1 Modifying webpage behavior using client-side scripting Javascript.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Input, Output, and Processing
Topic: An Introduction to JavaScript - from Beginning JavaScript by Wilton (WROX)
The Grammar of JavaScript.  Each line of a script is a statement  An instruction that JavaScript can evaluate (make sense of)  Ends with a semicolon;
Lesson Interactive Scripts JavaScript statements must go inside a script container, usually placed in the head section of the HTML document, but.
Numbers © Copyright 2014, Fred McClurg All Rights Reserved.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
Introducing JavaScript. Goals By the end of this lecture you should … Be able to describe the differences among object methods, object properties and.
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
Basic Data Types Numbers (integer and floating point)‏ Strings (sequences of characters)‏ Boolean values (true/false)‏
Conditional Statements.  Checking if input is a number  Radio buttons  Check boxes 2.
Variables, Expressions and Statements
Variables and Data Types Data (information we're going to store) – Numbers – Text – Dates What types of data can JavaScript process? How do we store it?
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 5 JavaScript.
JavaScript History and Versions JavaScript was introduced as part of the Netscape 2.0 browser Microsoft soon released its own version called JScript ECMA.
JS1-1 Introduction to JavaScript (JavaScript 1) Xingquan (Hill) Zhu
CSCE 102 – Chapter 11 (Performing Calculations) CSCE General Applications Programming Benito Mendoza Benito Mendoza 1 By Benito Mendoza.
JavaScript Assignment Statements Expressions Global Functions CST 200 JavaScript.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Variables.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Hazırlayan:Emin BORANDAĞ 2/17/ Numerik Değerler Kullanımı Integers are considered accurate up to 15 digits. Try it function myFunction() { var x.
JavaScript and Ajax (JavaScript Data Types) Week 2 Web site:
Project 4: Working with Variables Essentials for Design JavaScript Level One Michael Brooks.
Javascript Intro Instructor: Shalen Malabon. Lesson Plan Core Javascript Syntax Types and Objects Functions DOM Event Handling Debugging Javascript Smarter.
Expressions and Data Types Professor Robin Burke.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2012 CMPE-013/L Constants and Literals Gabriel Hugh Elkaim Spring 2012.
Checking If User Input Is Numeric.  Quiz  Detecting numeric input  Finish Prior Lecture  Y'all work on one of the problems listed 2.
Basic Objects. Math Object  Math.cos( x ), x in radians  Math.sqrt ( x )  Math.pow ( x, y )  Math.ceil( x )  etc.
1 HTML & teh internets. 2 Contents JavaScript CSS Goal: Integrating knowledge.
CSS Colors, JavaScript Variables, Conditionals and Basic Methods
Math class Random() method Floor method Top-level parseInt function
Programming the Web using XHTML and JavaScript
Scope, Objects, Strings, Numbers
14 A Brief Look at JavaScript and jQuery.
Web Systems Development (CSC-215)
CSS Colors, JavaScript Variables, Conditionals and Basic Methods
JavaScript Basics Stephen Delaney
Variables Kevin Harville.
Pertemuan 13 JavaScript.
JavaScript CS 4640 Programming Languages for Web Applications
Introducing JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Working with Numbers parseInt() and parseFloat() Math.round()
Chapter 5 JavaScript Numbers and Expressions
Presentation transcript:

Javascript

Javascript Tools Javascript Console Javascript Console Debugger Debugger DOM Inspector DOM Inspector

Numbers No real distinction between floating point and integers, internally, all numbers are fp No real distinction between floating point and integers, internally, all numbers are fp Octal integers begin with 0 and are followed by 0-7 (8,9 interpreted as decimals), these are not supported in the ECMA standard--you likely won't see an octal Octal integers begin with 0 and are followed by 0-7 (8,9 interpreted as decimals), these are not supported in the ECMA standard--you likely won't see an octal Hex integers begin with 0x, (0-9, a-f lower or uppercase), eg 0x10 is 16 in decimal Hex integers begin with 0x, (0-9, a-f lower or uppercase), eg 0x10 is 16 in decimal Octal and hex numbers can be negative, but cannot have a decimal portion nor support scientific notation. Octal and hex numbers can be negative, but cannot have a decimal portion nor support scientific notation. You're likely to run into issues mainly where you use an illegal number unknowingly…. You're likely to run into issues mainly where you use an illegal number unknowingly….

Invalid Numbers (00 marks octal, which can't have a decimal) (00 marks octal, which can't have a decimal) 0x3.45 (0x marks hex, and decimals aren’t allowed) 0x3.45 (0x marks hex, and decimals aren’t allowed) 0378 (value of 378 even tho marked as an octal, since 8 coerces interpretation as a decimal number) 0378 (value of 378 even tho marked as an octal, since 8 coerces interpretation as a decimal number)

Zero and Special Numbers Null is not a 0 (although it sometimes acts like it is Null is not a 0 (although it sometimes acts like it is Undefined values act differently (they are NAN, or Not a Number) Undefined values act differently (they are NAN, or Not a Number) +0 and -0 not the same +0 and -0 not the same +infinity and -infinity not the same +infinity and -infinity not the same

Math 12how_old.html Standard Math functions supported (+, -, *, /, etc.) Standard Math functions supported (+, -, *, /, etc.) Use parseInt() or parseFloat() method to treat variables as numbers Use parseInt() or parseFloat() method to treat variables as numbers Precedence is important! Precedence is important! var x = prompt ("What Year Is It?"); var y = prompt ("What Year Were You Born",""); document.write ("You're " + (parseInt(x)-parseInt(y)) + " years old");

Coercion A variable of one type can be used as if it were another. A variable of one type can be used as if it were another. If there's a conflict, javascript doesn't produce an exception If there's a conflict, javascript doesn't produce an exception string+number goes to strings string+number goes to strings boolean+string goes to strings boolean+string goes to strings number+boolean goes to numbers number+boolean goes to numbers Explicit conversions Explicit conversions string to an integer, use the parseInt method. string to an integer, use the parseInt method. string to a number, use the parseFloat method. string to a number, use the parseFloat method.

Coercion 15math_parse.html Javascript and typing can be a mess Javascript and typing can be a mess var x = prompt ("value of x",""); // use parseFloat() to convert x to a number var x_fp = parseFloat(x); document.write("x is has a type of " + typeof x + " "); + typeof x + " "); document.write("x_fp has a type of " + typeof x_fp + " "); + typeof x_fp + " ");</script>

Digression: Dealing with Forms In these recent examples, I've been prompting the user for data via an alert box--bad idea In these recent examples, I've been prompting the user for data via an alert box--bad idea You can use an HTML form instead--javascript can read and assign values to form objects You can use an HTML form instead--javascript can read and assign values to form objects You have to identify the objects, so name them You have to identify the objects, so name them

Math and Strings Like we saw in php, javascript's coercion can lead to errors Like we saw in php, javascript's coercion can lead to errors See math2.html and math3.html See math2.html and math3.html var x = prompt ("value of x",""); var y = prompt ("value of y",""); document.write("x * y = " + x*y + " "); document.write("x + y = " + x + y + " ");

Quick Review An object is just a collection of properties, values, and methods given a name An object is just a collection of properties, values, and methods given a name

Math Object Math is also an object Math is also an object document.write("The value of PI is: " + Math.PI + " "); + " "); document.write("A random number is: " + Math.random() + " "); + " "); document.write("The square root of 156 is: " + Math.sqrt(156) + " "); + Math.sqrt(156) + " "); document.write("The square root of 156 rounded is: " + Math.round(Math.sqrt(156)) + " "); + Math.round(Math.sqrt(156)) + " ");</script> 08Math_Object.html

Creating your own object You can create an object with an "array" of characteristics and values You can create an object with an "array" of characteristics and values We'll look at this in more detail later… We'll look at this in more detail later… // Create an object named obj var obj = { name: "Carrot", name: "Carrot", "for": "Max", "for": "Max", details: { details: { color: "orange", color: "orange", size: 12 size: 12 } object.html

Arrays Javascript supports single dimensional arrays, and arrays of arrays Javascript supports single dimensional arrays, and arrays of arrays var phrases = new Array() phrases[1] = 'Hi there!'; phrases[2] = 'Having fun?'; phrases[3] = 'Glad to hear!'; phrases[4] = 'Bubbadee, that\'s all folks.'; phrases[5] = 'Well, maybe one more time!';