JavaScript: The First Parts Part Three Douglas Crockford Yahoo! Inc.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
L16. Cell Arrays Set-Up Subscripting Nested Loops String Manipulations.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
JavaScript: The First Parts Part Four Douglas Crockford Yahoo! Inc.
Advanced JS The World's Most Misunderstood Programming Language ) Douglas Crockford( Shimon Dahan
Insight Through Computing 16. Cell Arrays Set-Up Subscripting Nested Loops String Manipulations.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
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.
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.
Lecture 7 C Pointers Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
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.
Games and Simulations O-O Programming in Java The Walker School
By.. Miss Prangtip Kaewsuphot
Taking JavaScript Seriously IS NOT THE WORST IDEA.
JavaScript JavaScript is a scripting language that is most commonly used to add client- side programming to a web page. Some of the things it is used for.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Data types, Literals (constants) and Variables Data types specify what kind of data, such as numbers and characters, can be stored and manipulated within.
Roman Numerals Learning objective: To learn how to count using Roman numerals.
1 EPSII 59:006 Spring Exam Dates 3 Homework Grading In general, programs that do not compile and run will be given no more than 25% credit Points.
Introduction to JavaScript Gordon Tian
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
CS346 Javascript -3 Module 3 JavaScript Variables.
Basic Data Types Numbers (integer and floating point)‏ Strings (sequences of characters)‏ Boolean values (true/false)‏
Variety of JavaScript Examples Please use speaker notes for additional information!
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
 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.
JavaScript History and Versions JavaScript was introduced as part of the Netscape 2.0 browser Microsoft soon released its own version called JScript ECMA.
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
JavaScript: The First Parts Part One Douglas Crockford Yahoo! Inc.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
JavaScript: The First Parts Part Two Douglas Crockford Yahoo! Inc.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
JavaScript and Ajax (JavaScript Data Types) Week 2 Web site:
CGS 3066: Web Programming and Design Spring 2016 Programming in JavaScript.
Expressions and Data Types Professor Robin Burke.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Click to add Text Javascript Presented by Bunlong VAN Basic.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
Maths in Year 3 at St Anselm’s.
Introduction to Calculated Columns Variables, Conditionals, and String Manipulation PRESENTER: Cameron Blashka| Informer Implementation Specialist| April.
CGS 3066: Web Programming and Design Spring 2017
>> Introduction to JavaScript
A variable is a name for a value stored in memory.
CprE 185: Intro to Problem Solving (using C)
Computer Programming I
Scope, Objects, Strings, Numbers
Chapter 19 JavaScript.
.Net Programming with C#
WEB PROGRAMMING JavaScript.
Roman Numerals.
Write these notes in your spirals!
Roman Numerals.
Roman Numerals.
Roman Numerals.
CGS 3066: Web Programming and Design Spring 2016
Presentation transcript:

JavaScript: The First Parts Part Three Douglas Crockford Yahoo! Inc.

Review average_array([1, 2, 3, 4]) // 2.5

Review average_array([1, 2, 3, 4]) // 2.5 average_array([1, 2, 3, 4, 5]) // 3 average_array([1, 2]) // 1.5

Review var average_array = function (array) { var i, total = 0; for (i = 0; i < array.length; i = i + 1) { total += array[i]; } return total / array.length; };

Learn to Program Values Variables Expressions Branching Loops Functions Recursion Arrays Objects Trees

Values Booleans Numbers Strings null undefined

Strings Textual values, a sequence of 0 or more characters. Unicode: Able to represent all of the characters of all languages. Internally, each character is represented as a 16-bit number. A string containing nothing is called the empty string.

String Literals Wrapped in "..." or '...'. No line breaks. Escapement with \. "\"" === '"'

String Operators + does concatenation 'c' + 'a' + 't' === 'cat' The.charAt(index) method can get a character. 'cat'.charAt(1) === 'a' The.length member gives the number of characters in the string. 'cat'.length === 3 The.toLowerCase() method can produce a lowercase copy. 'CAT'.toLowerCase() === 'cat'

a = '"' b = 'C' + 'A' + 'T' b.length c = b.toLowerCase() d = c.charAt(0) e = c.charAt(1) f = c.charAt(3) c = 'bad ' + c h = '1'

Scope 1.Parameters and variables defined inside of a function are not visible outside of the function. 2.Functions can be created inside of other functions. 3.The parameters and variables of an outer function are visible to the inner function.

View : Page Source

var roman = function () { var table = [ ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'], ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'], ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'] ]; return function (n) { var result = '', i; for (i = 0; i < table.length; i += 1) { result = table[i][n % 10] + result; n = Math.floor(n / 10); } for (i = 0; i < n; i += 1) { result = 'M' + result; } return result; }; }();

Debugger Click on the bug icon on the bottom bar. Enable / apply script debugging. Click on the script tab. Drag the top edge of the debugger window up to get a larger view. Click on the line number 24 producing a red breakpoint.

Debugger Type in 1666 and press enter. Run Step Over Step Into Step Out Close

Object A container of name value/pairs. Objects are a useful way to collect and organize information.

Object literal var my_data = { first_name: 'Douglas', last_name: 'Crockford', height: 74 }; my_data['height'] === my_data.height var name = my_data.first_name + ' ' + my_data.last_name;

o = {} c = 'cat' o[c] = 'Muldoon' o['dog'] = 'Mutt' o.cat o[c] o.dog o.v = 5 o.x = 10

Branching Execute part of a function depending on the value of an expression. if (expression) { // executed only if the expression is true }

Branching if (expression) { // executed only if the expression is true } else { // executed only if the expression is false }

Branching if (expression1) { // executed only if expression1 is true } else if (expression2) { // executed only if expression2 is true } else if (expression3) { // executed only if expression3 is true } else { // executed only if all of the expressions were false }

Branching if (expression1) { if (expression2) { // executed only if expression1 // and expression2 are true } else { // executed only if the expression1 is true // and expression2 is false } } else { if (expression3) { // executed only if expression1 is false // and expression3 is true } else { // executed only if the expression1 is false // and expression3 is false }

Branching var min_array = function (array) { var i, value = Infinity; for (i = 0; i < array.length; i = i + 1) { if (array[i] < value) { value = array[i]; } return value; };

Assignment 3 Write program deroman that takes a string and produces a number. Use roman.html as a template. Use.toLowerCase() to convert the string to lower case. Use an object to map the Roman letters to number values. If the value of a character is less than the value of the next character, then subtract its value from the result. Otherwise, add its value to the result. Always add the last character's value.