Javascript Step by Step, Third Edition

Javascript Step by Step, Third Edition

JavaScript Step by Step, Third Edition Steve Suehring Copyright © 2013 by Steve Suehring All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. ISBN: 978-0-7356-6593-4 3 4 5 6 7 8 9 10 11 LSI 8 7 6 5 4 3 Printed and bound in the United States of America. Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Book Support at [email protected]. Please tell us what you think of this book at http://www.microsoft.com/learning/booksurvey. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/ Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions and Developmental Editor: Russell Jones Production Editor: Melanie Yarbrough Editorial Production: nSight, Inc. Technical Reviewer: John Grieb Copyeditor: nSight, Inc. Indexer: nSight, Inc. Cover Design: Twist Creative • Seattle Cover Composition: Karen Montgomery Illustrator: nSight, Inc. [2013-09-09] I would like to dedicate this book to Mom and Dad. —STEVE SUEHRING Contents at a glance Introduction xix Part I JAVAWHAT? THE WHERE, WHY, AND HOW OF JAVASCRIPT CHAPTER 1 JavaScript is more than you might think 3 CHAPTER 2 Developing in JavaScript 17 CHAPTER 3 JavaScript syntax and statements 29 CHAPTER 4 Working with variables and data types 41 CHAPTER 5 Using operators and expressions 79 CHAPTER 6 Controlling flow with conditionals and loops 93 CHAPTER 7 Working with functions 119 CHAPTER 8 Objects in JavaScript 133 CHAPTER 9 The Browser Object Model 151 CHAPTER 10 An introduction to JavaScript libraries and frameworks 169 CHAPTER 11 An introduction to jQuery 173 Part II INTEGRATING JAVASCRIPT INTO DESIGN CHAPTER 12 The Document Object Model 193 CHAPTER 13 JavaScript events and the browser 215 CHAPTER 14 Working with images in JavaScript 235 CHAPTER 15 Using JavaScript with web forms 257 CHAPTER 16 JavaScript and CSS 277 CHAPTER 17 jQuery effects and plug-ins 289 CHAPTER 18 Mobile development with jQuery Mobile 307 CHAPTER 19 Getting data into JavaScript 327 Part III AJAX AND SERVER-SIDE INTEGRATION CHAPTER 20 Using AJAX 335 CHAPTER 21 Developing for Windows 8 353 Part IV JAVASCRIPT AND WINDOWS 8 CHAPTER 22 Using Visual Studio for Windows 8 development 363 CHAPTER 23 Creating a Windows app 381 APPENDIX A Answer key to exercises 403 APPENDIX B Writing JavaScript with other tools 425 Index 439 vi Contents at a Glance Contents Introduction ....................................................xix Part I JAVAWHAT? THE WHERE, WHY, AND HOW OF JAVASCRIPT Chapter 1 JavaScript is more than you might think 3 A brief history of JavaScript. 3 Enter Internet Explorer 3.0. .4 And then came ECMAScript ...................................4 So many standards... .........................................5 The DOM ...................................................5 What’s in a JavaScript program? ....................................6 JavaScript placement on your webpage ..............................7 What JavaScript can do ...........................................10 What JavaScript can’t do ..........................................10 JavaScript can’t be forced on a client ..........................10 JavaScript can’t guarantee data security .......................11 JavaScript can’t cross domains ................................11 JavaScript doesn’t do servers .................................12 Tips for using JavaScript ...........................................12 Where JavaScript fits ........................................14 Which browsers should the site support? ......................15 And then came Windows 8 ........................................15 Exercises ........................................................16 What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: microsoft.com/learning/booksurvey vii Chapter 2 Developing in JavaScript 17 JavaScript development options ...................................17 Configuring your environment .....................................18 Writing JavaScript with Visual Studio 2012 ..........................19 Your first web (and JavaScript) project with Visual Studio 2012 ...19 Using external JavaScript files with Visual Studio 2012 ...........23 Debugging JavaScript ............................................27 Exercises ........................................................27 Chapter 3 JavaScript syntax and statements 29 A bit of housekeeping ............................................29 Case sensitivity .............................................29 White space. .30 Comments .................................................31 Semicolons ................................................32 Line breaks ................................................33 Placing JavaScript correctly ..................................33 JavaScript statements .............................................34 What’s in a statement? ......................................34 The two types of JavaScript statements ........................35 Reserved words in JavaScript ......................................35 A quick look at functions ..........................................36 JavaScript’s strict mode ...........................................38 Exercises ........................................................39 Chapter 4 Working with variables and data types 41 Data types in JavaScript ...........................................41 Working with numbers ......................................42 Working with strings ........................................47 Booleans ..................................................50 Null ...................................................... 50 Undefined ................................................. 50 viii Contents Objects ....................................................51 Arrays .....................................................51 Defining and using variables .......................................52 Declaring variables ..........................................52 Variable types. .53 Variable scope ..............................................53 The Date object ............................................61 Using the RegExp object ..........................................70 The syntax of regular expressions .............................71 References and garbage collection ............................75 Learning about type conversions ...................................76 Number conversions ........................................76 String conversions ..........................................76 Boolean conversions ........................................76 Exercises ........................................................77 Chapter 5 Using operators and expressions 79 Meet the operators ...............................................79 Additive operators ...............................................80 Multiplicative operators ...........................................80 Bitwise operators ................................................81 Equality operators ................................................81 Relational operators ..............................................83 The in operator .............................................84 The instanceof operator .....................................85 Unary operators .................................................85 Incrementing and decrementing. .85 Converting to a number with the plus sign. 86 Creating a negative number with the minus sign ...............86 Negating with bitwise not and logical not ..................... 86 Using the delete operator ....................................87 Returning variable types with the typeof operator ..............88 Contents ix Assignment operators ............................................90 The comma operator .............................................91 Exercises ........................................................92 Chapter 6 Controlling flow with conditionals and loops 93 If (and how) .....................................................93 Syntax for if statements. .94 The prompt() function in Internet Explorer. 95 Compound conditions .......................................98 Using else if and else statements ..................................101 Working with ternary conditionals ................................106 Testing with switch ..............................................106 Looping with while ..............................................108 The while statement ........................................108 The do...while statement ....................................110

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    96 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us