Pehlivanian, A. and Nguyen, D. (2013) Jump Start JavaScript – Get Up to Speed with JavaScript in a Weekend, Jump Start Series, SitePoint Pty, Ltd.
Download eBook PDF (PDF 2,902KB)
Download Source Code (ZIP 69KB)
Get a Jump Start on JavaScript today!
JavaScript is a key technology in modern web development, enabling you to craft interactive, usable and engaging experiences for your users.
In just one weekend with this SitePoint book, you’ll learn how to:
- Use JavaScript to solve real world problems: build forms, track user events and craft animations
- Use JavaScript with HTML5 and CSS3
- Build an entire JavaScript-powered application from scratch: a task management application
Plus you’ll discover how to use modern techniques such as Canvas and Ajax.
JavaScript is the lifeblood of today’s web. If you’re going to learn one new language this year, make sure it’s JavaScript.
Take a quick peek under the hood of the largest social network giant or the smallest bedroom startup, and what will you find? JavaScript. Pages and pages of JavaScript. Twitter, Facebook, and Google are all living, breathing JavaScript beings. It’s the beating heart of the modern web!
Whether you’re a back-end dev, front-end dev or designer, Jump Start JavaScript is the perfect primer to what may be the single most valuable language to know for the coming decade.
What will I learn?
- Nail the JavaScript FUNDAMENTALS you’ll need to get started
- Make the DOM dance: CONTROL every element on your page with ease
- Master the CANVAS: Create compelling games, apps & interactive graphics live in the browser
- Build perfectly tailored JavaScript SOLUTIONS to the problem in front of you
- Construct a dynamic JavaScript-powered to-do list app while you’re learning
Who should read this book?
Beginner level web developers. Reasonable knowledge of HTML and CSS is assumed. It’s a fast paced tutorial so may be unsuitable for absolute tech newbies.
McFarland, D. S. (2008) JavaScript – The Missing Manual, Missing Manuals, O’Reilly Media, Inc.
A more recent version of this book is available.
Download eBook PDF (PDF 8,827KB)
Download Source Files (ZIP 1,645KB)
Publisher’s Web Site: http://shop.oreilly.com/product/9780596515898.do
JavaScript is an essential language for creating modern, interactive websites, but its complex rules challenge even the most experienced web designers. With JavaScript: The Missing Manual, you’ll quickly learn how to use JavaScript in sophisticated ways — without pain or frustration — even if you have little or no programming experience.
JavaScript expert David McFarland first teaches you the basics by having you build a simple program. Then you’ll learn how to work with jQuery, a popular library of pre-built JavaScript components that’s free and easy to use. With jQuery, you can quickly build modern, interactive web pages — without having to script everything from scratch!
- Learn how to add scripts to a web page, store and manipulate information, communicate with the browser window, respond to events like mouse clicks and form submissions, and identify and modify HTML
- Get real-world examples of JavaScript in action
- Learn to build pop-up navigation bars, enhance HTML tables, create an interactive photo gallery, and make web forms more usable
- Create interesting user interfaces with tabbed panels, accordion panels, and pop-up dialog boxes
- Learn to avoid the ten most common errors new programmers make, and how to find and fix bugs
- Use JavaScript with Ajax to communicate with a server so that your web pages can receive information without having to reload
Table of Contents
Introduction;
- What Is JavaScript?;
- HTML: The Barebones Structure;
- CSS: Adding Style to Web Pages;
- Software for JavaScript Programming;
- About This Book;
- The Very Basics;
Part I: Getting Started with JavaScript;
Chapter 1: Writing Your First JavaScript Program;
- 1.1 Introducing Programming;
- 1.2 How to Add JavaScript to a Page;
- 1.3 Your First JavaScript Program;
- 1.4 Writing Text on a Web Page;
- 1.5 Attaching an External JavaScript File;
- 1.6 Tracking Down Errors;
Chapter 2: The Grammar of JavaScript;
- 2.1 Statements;
- 2.2 Commands;
- 2.3 Types of Data;
- 2.4 Variables;
- 2.5 Working with Data Types and Variables;
- 2.6 Tutorial: Using Variables to Create Messages;
- 2.7 Tutorial: Asking for Information;
- 2.8 Arrays;
- 2.9 Tutorial: Writing to a Web Page Using Arrays;
- 2.10 Comments;
Chapter 3: Adding Logic and Control to Your Programs;
- 3.1 Making Programs React Intelligently;
- 3.2 Tutorial: Using Conditional Statements;
- 3.3 Handling Repetitive Tasks with Loops;
- 3.4 Functions: Turn Useful Code Into Reusable Commands;
- 3.5 Tutorial: A Simple Quiz;
Chapter 4: Working with Words, Numbers, and Dates;
- 4.1 A Quick Object Lesson;
- 4.2 Strings;
- 4.3 Finding Patterns in Strings;
- 4.4 Numbers;
- 4.5 Dates and Times;
- 4.6 Tutorial;
Chapter 5: Dynamically Modifying Web Pages;
- 5.1 Modifying Web Pages: An Overview;
- 5.2 Understanding the Document Object Model;
- 5.3 Introducing JavaScript Libraries;
- 5.4 Selecting Page Elements (Revisited);
- 5.5 Adding Content to a Page;
- 5.6 Setting and Reading Tag Attributes;
- 5.7 Reading, Setting, and Removing HTML Attributes;
- 5.8 Creative Headlines;
- 5.9 Acting on Each Element in a Selection;
- 5.10 Automatic Pull Quotes;
Chapter 6: Action/Reaction: Making Pages Come Alive with Events;
6.1 What Are Events?;
6.2 Using Events with Functions;
6.3 Tutorial: Highlighting Table Rows;
6.4 More jQuery Event Concepts;
6.5 Advanced Event Management;
6.6 Tutorial: A One-Page FAQ;
Chapter 7: Improving Your Images;
- 7.1 Swapping Images;
- 7.2 Tutorial: Adding Rollover Images;
- 7.3 jQuery Effects;
- 7.4 Tutorial: Photo Gallery with Effects;
- 7.5 Advanced Gallery with jQuery lightBox;
- 7.6 Tutorial: lightBox Photo Gallery;
- 7.7 Animated Slideshows with Cycle;
- 7.8 Tutorial: An Automated Slideshow;
Part II: Building Web Page Features;
Chapter 8: Improving Navigation;
- 8.1 Some Link Basics;
- 8.2 Opening External Links in a New Window;
- 8.3 Creating New Windows;
- 8.4 Opening Pages in a Window on the Page;
- 8.5 Tutorial: Making Bigger Links;
- 8.6 Animated Navigation Menus;
Chapter 9: Enhancing Web Forms;
- 9.1 Understanding Forms;
- 9.2 Adding Smarts to Your Forms;
- 9.3 Tutorial: Basic Form Enhancements;
- 9.4 Form Validation;
- 9.5 Validation Tutorial;
Chapter 10: Expanding Your Interface;
- 10.1 Hiding Information with Accordion Panels;
- 10.2 Organizing Information in Tabbed Panels;
- 10.3 Tooltips;
- 10.4 Creating Sortable Tables;
Part III: Ajax: Communicating with the Web Server;
Chapter 11: Introducing Ajax;
- 11.1 What Is Ajax?;
- 11.2 Ajax: The Basics;
- 11.3 Ajax the jQuery Way;
- 11.4 JSON;
Chapter 12: Basic Ajax Programming;
- 12.1 Tabs Plug-in;
- 12.2 Adding Google Maps to Your Site;
Part IV: Troubleshooting, Tips, and Tricks;
Chapter 13: Troubleshooting and Debugging;
- 13.1 Top JavaScript Programming Mistakes;
- 13.2 Debugging with Firebug;
- 13.3 Debugging Tutorial;
Chapter 14: Going Further with JavaScript;
- 14.1 Putting It All Together;
- 14.2 Writing More Efficient JavaScript;
- 14.3 Creating Fast-Loading JavaScript;
Part V: Appendix;
JavaScript Resources;
- References;
- Basic JavaScript;
- jQuery;
- The Document Object Model;
- Ajax;
- Advanced JavaScript;
- CSS;
- JavaScript Software;
- Introduction
- Part I: Getting Started with JavaScript
- Chapter 1: Writing Your First JavaScript Program
- Chapter 2: The Grammar of JavaScript
- Chapter 3: Adding Logic and Control to Your Programs
- Chapter 4: Working with Words, Numbers, and Dates
- Chapter 5: Dynamically Modifying Web Pages
- Chapter 6: Action/Reaction: Making Pages Come Alive with Events
- Chapter 7: Improving Your Images
- Part II: Building Web Page Features
- Chapter 8: Improving Navigation
- Chapter 9: Enhancing Web Forms
- Chapter 10: Expanding Your Interface
- Part III: Ajax: Communicating with the Web Server
- Chapter 11: Introducing Ajax
- Chapter 12: Basic Ajax Programming
- Part IV: Troubleshooting, Tips, and Tricks
- Chapter 13: Troubleshooting and Debugging
- Chapter 14: Going Further with JavaScript
- Part V: Appendix
- JavaScript Resources
If you know HTML and/or CSS and want to take your skills to the next level, or even if you are a complete web novice, you really need to learn JavaScript. Not only is it the language behind the smooth and dynamic operation of Web 2.0 websites like Facebook, Twitter and Gmail, but in conjunction with HTML5 it’s also the standard means Microsoft supports for creating Windows 8 apps – JavaScript is definitely the future for Windows! So, whether you want to simply add a little functionality to your website, such as smooth menus that pop up and down, image transition effects, user-friendly form handling and verification, or anything else that’s more than a simple, flat HTML/CSS design, JavaScript is the way to go. What’s more, JavaScript is easy. If you’ve ever tried to learn it and been put off by a plethora of jargon and technical mumbo-jumbo then you’re in for a real treat, because Robin Nixon’s Crash Courses have helped tens of thousands of people learn the new skills they need. From the top-selling author of Learning PHP, MySQL & JavaScript, and starting from the ground up with no assumption of prior knowledge, every aspect of JavaScript is explained in this book, in logical order with plenty of simple examples, clear explanations, informative figures, and advice on how best to use the new things you learn. If you want to learn JavaScript up to a solid intermediate level, this book will teach you all you need to know, without recourse to other books and materials. Plus all the examples are free to download from the companion website, so you won’t have to type them in to follow along and try them out for yourself. This course features the following lectures:
- Introduction to JavaScript
- Incorporating JavaScript Code Into a Web Page
- JavaScript Language Syntax
- JavaScript Operators
- JavaScript Arrays
- Multidimensional Arrays
- The JavaScript Array Functions
- Controlling Program Flow
- Looping Sections of Code
- JavaScript Functions
- JavaScript Objects
- Errors and Expressions
- The Document Object Model
- Advanced JavaScript
- Appendix: 150+ Functions Detailed
Reasons why you will learn all you need from this course:
- No assumption is made of previous knowledge.
- Every new concept is explained in logical order.
- Fully-tested examples are provided throughout.
- Each lecture features several notes offering extra, handy advice.
- The examples can all be downloaded free from the companion website.
Complete with best practices and examples of JavaScript use, this new edition shows you how to integrate the language with the browser environment, and how to practice proper coding techniques for standards-compliant websites. This book will help you:
- Learn the JavaScript application structure, including basic statements and control structures
- Identify JavaScript objects—String, Number, Boolean, Function, and more
- Use browser debugging tools and troubleshooting techniques
- Understand event handling, form events, and JavaScript applications with forms
- Develop with the Browser Object Model, the Document Object Model, and custom objects you create
- Learn about browser cookies and more modern client-side storage techniques
- Get details for using XML or JSON with Ajax applications
Learning JavaScript follows proven learning principles to help you absorb the concepts at an easy pace, so you’ll learn how to create powerful and responsive applications in any browser.
Table of Contents
Preface; Audience; Assumptions and Approach; How the Book Is Organized; Conventions Used in This Book; Using Code Examples; Safari® Books Online; How to Contact Us; Acknowledgments; Chapter 1: Hello JavaScript!; 1.1 Hello World!; 1.2 Hello World! Once Again; 1.3 JavaScript Files; 1.4 Accessibility and JavaScript Best Practices; Chapter 2: JavaScript Data Types and Variables; 2.1 Identifying Variables; 2.2 Primitive Types; 2.3 The String Data Type; 2.4 The Boolean Data Type; 2.5 The Number Data Type; 2.6 The null and undefined Variables; 2.7 Constants: Named but Not Variables; 2.8 Test Your Knowledge: Quiz; 2.9 Test Your Knowledge: Answers; Chapter 3: Operators and Statements; 3.1 The Format of a JavaScript Statement; 3.2 The Assignment Statement; 3.3 Conditional Statements and Program Flow; 3.4 The Conditional Operators; 3.5 The Logical Operators; 3.6 Advanced Statements: The Loops; 3.7 Test Your Knowledge: Quiz; 3.8 Test Your Knowledge: Answers; Chapter 4: The JavaScript Objects; 4.1 Primitive Data Types As Objects; 4.2 Boolean, Number, and String; 4.3 Regular Expressions and RegExp; 4.4 The Date Object; 4.5 The Math Object; 4.6 JavaScript Arrays; 4.7 Test Your Knowledge: Quiz; 4.8 Test Your Knowledge: Answers; Chapter 5: Functions; 5.1 Declarative Functions; 5.2 Anonymous Functions; 5.3 Function Literals; 5.4 Function Type Summary; 5.5 Function Scope; 5.6 Function As Object; 5.7 Test Your Knowledge: Quiz; 5.8 Test Your Knowledge: Answers; Chapter 6: Troubleshooting, Debugging, and Cross-Browser Issues; 6.1 Simple Ways to Debug; 6.2 Development and Debugging Tools by Browser; 6.3 Dealing with Cross-Browser Differences; 6.4 Test Your Knowledge: Quiz; 6.5 Test Your Knowledge: Answers; Chapter 7: Catching Events; 7.1 The Events; 7.2 Level 0 Event Handling; 7.3 The DOM Level 2 Event Model; 7.4 Test Your Knowledge: Quiz; 7.5 Test Your Knowledge: Answers; Chapter 8: Forms, Form Events, and Validation; 8.1 Attaching Events to Forms: Different Approaches; 8.2 Selection; 8.3 Radio Buttons and Checkboxes; 8.4 The text, textarea, password, and hidden Input Elements; 8.5 Input Fields and Regular Expression Validation; 8.6 Forms, the Sandbox, and XSS; 8.7 Test Your Knowledge: Quiz; 8.8 Test Your Knowledge: Answers; Chapter 9: Browser As Puzzle Box; 9.1 The Structure of the Browser at a Glance; 9.2 The window Object; 9.3 Creating and Controlling Windows; 9.4 Frames; 9.5 Adding and Controlling Timers; 9.6 The history, screen, and navigator Objects; 9.7 The Document Object; 9.8 innerHTML; 9.9 Test Your Knowledge: Quiz; 9.10 Test Your Knowledge: Answers; Chapter 10: Cookies and Other Client-Side Storage Techniques; 10.1 The JavaScript Sandbox and Cookie Security; 10.2 All About Cookies; 10.3 Flash Shared Objects, Google Gears, and HTML5 DOM Storage; 10.4 Test Your Knowledge: Quiz; 10.5 Test Your Knowledge: Answers; Chapter 11: The DOM, or Web Page As Tree; 11.1 A Tale of Two Interfaces; 11.2 The DOM HTML API; 11.3 Understanding the DOM: The Core API; 11.4 Element and Access in Context; 11.5 Modifying the Tree; 11.6 Test Your Knowledge: Quiz; 11.7 Test Your Knowledge: Answers; Chapter 12: Dynamic Pages; 12.1 JavaScript, CSS, and the DOM; 12.2 Fonts and Text; 12.3 Position and Movement; 12.4 Size and Clipping; 12.5 Display, Visibility, and Opacity; 12.6 Revisiting the DOM: Collapsing Forms, Query Selectors, and Class Names; 12.7 Test Your Knowledge: Quiz; 12.8 Test Your Knowledge: Answers; Chapter 13: Creating Custom JavaScript Objects; 13.1 The JavaScript Object and Prototyping; 13.2 Creating Your Own Custom JavaScript Objects; 13.3 Object Encapsulation; 13.4 Chaining Constructors and JavaScript Inheritance; 13.5 One-Off Objects; 13.6 Object Libraries: Packaging Your Objects for Reuse; 13.7 Advanced Error Handling Techniques (try, throw, catch); 13.8 Test Your Knowledge: Quiz; 13.9 Test Your Knowledge: Answers; Chapter 14: Moving Outside the Page with Ajax; 14.1 How Ajax Works; 14.2 Hello Ajax World!; 14.3 The XMLHttpRequest Object and Preparing to Send the Request; 14.4 Processing the Web Request Return; 14.5 Ajax: It’s Not Only Code; 14.6 JavaScript and Ajax Libraries; 14.7 Test Your Knowledge: Quiz; 14.8 Test Your Knowledge: Answers; Chapter 15: Ajax Data: XML or JSON?; 15.1 XML-Formatted Ajax Results; 15.2 JavaScript Object Notation; 15.3 Test Your Knowledge: Quiz; 15.4 Test Your Knowledge: Answers; Colophon;|
- Preface
- Chapter 1: Hello JavaScript!
- Chapter 2: JavaScript Data Types and Variables
- Chapter 3: Operators and Statements
- Chapter 4: The JavaScript Objects
- Chapter 5: Functions
- Chapter 6: Troubleshooting, Debugging, and Cross-Browser Issues
- Chapter 7: Catching Events
- Chapter 8: Forms, Form Events, and Validation
- Chapter 9: Browser As Puzzle Box
- Chapter 10: Cookies and Other Client-Side Storage Techniques
- Chapter 11: The DOM, or Web Page As Tree
- Chapter 12: Dynamic Pages
- Chapter 13: Creating Custom JavaScript Objects
- Chapter 14: Moving Outside the Page with Ajax
- Chapter 15: Ajax Data: XML or JSON?
- Colophon
It’s time for a current, definitive JavaScript book, and in this comprehensive beginner’s guide, bestselling author Larry Ullman teaches the language as it is implemented today. Larry demonstrates how to build upon JavaScript’s ease of use, while demystifying its often-cryptic syntax, especially for those who have not programmed before. This book enforces modern JavaScript’s best practices and embraces key Web development approaches such as progressive enhancement and unobtrusive scripting. The author demonstrates loads of real-world code and makes it available for download.
You’ll learn about JavaScript itself and the relationship between JavaScript and HTML. Next you’ll explore variables, common operators, and control structures. Then you’ll create functions, handle events, and do more with HTML forms. You’ll master Ajax, work with frameworks, and use JavaScript with PHP to create a complete example. The result is a book that helps you not just tinker with JavaScript but to thoroughly comprehend it.
This book includes:
- Easy step-by-step instruction, ample illustrations, and clear examples
- Real-world techniques to build your skills
- Insight into best practices from a veteran Web expert
- Emphasis on strategies for creating reliable code that will work on all of today’s browsers and devices, even those without JavaScript
Table of Contents
Introduction
About This Book
What You’ll Need
About the Author
Getting Support
Part 1: Getting Started
Chapter 1: (Re-)Introducing JavaScript
What is JavaScript?
JavaScript Versions and Browser Support
JavaScript Programming Goals
Chapter 2: JavaScript in Action
Choosing a DOCTYPE
Introducing HTML5
Embedding JavaScript in HTML
JavaScript Approaches
Cobbling Together Some Code
A Framework Approach
Steal This JavaScript
Chapter 3: Tools of the Trade
The Great Debate: Text Editors vs. IDEs
The Browser: Your Friend, Your Enemy
Executing JavaScript
Debugging Fundamentals
Online Resources
Part 2: JavaScript Fundamentals
Chapter 4: Simple Variable Types
Basic Variable Syntax
Common Operators
Working with Numbers
Working with Strings
Other Simple Types
Performing Type Conversions
Generating Dates and Times
Chapter 5: Using Control Structures
Conditionals
What is true?
Logical Operators
Comparison Operators
Preventing Bugs
Performing Iterations
Chapter 6: Complex Variable Types
Working with Arrays
Working with Objects
Arrays as Objects
Comparing Types
Chapter 7: Creating Functions
Defining Your Own Functions
Passing Values to Functions
Returning Values from Functions
Understanding Variable Scope
Anonymous Functions
Nested Functions
Functions Acting as Classes
Function Prototypes
Nested Functions
Chapter 8: Event Handling
Event Phases
Browser Events
Keyboard Events
Input Device Events
Accessible Events
Assigning Event Handlers
Creating an Event Assigner
Referencing the Event
Preventing Default Event Behavior
Chapter 9: JavaScript and the Browser
DOM Manipulation
JavaScript and CSS
Alerts and Prompts
The Window
Chapter 10: Working with Forms
Handling Form Submissions
Form Validation
Using Regular Expressions
Handling File Uploads
Chapter 11: Ajax
Understanding Ajax
Providing Dynamic Content
Form Validation
Ajax Performance Tips
Working with Other Data
Chapter 12: Error Management
Simple Debugging Errors
Handling Problems Gracefully
Creating Informative Errors
Creating Useful Errors
Throwing Exceptions
Part 3: Next Steps
Chapter 13: Frameworks
Choosing a Framework
Introducing jQuery
Introducing ExtJS
Introducing YUI
Chapter 14: Advanced JavaScript
Unit Testing
Profiling
Closures
Prototypes
Namespaces
Minifying
Chapter 15: Putting It All Together
- Introduction
- Welcome to JavaScript
- Part 1: Getting Started
- Chapter 1: (Re-)Introducing JavaScript
- What is JavaScript?
- JavaScript’s History
- JavaScript Isn’t…
- How JavaScript Compares To…
- Why JavaScript is a Good Thing
- JavaScript Versions and Browser Support
- JavaScript Programming Goals
- Wrapping Up
- Chapter 2: JavaScript in Action
- Choosing a Doctype
- An HTML5 Primer
- Adding JavaScript to HTML
- Key Development Approaches
- Cobbling Together Some Code
- Steal This JavaScript
- Wrapping Up
- Chapter 3: Tools of the Trade
- The Great Debate: Text Editor or IDE?
- The Browser: Your Friend, Your Enemy
- Testing on Multiple Browsers
- Testing JavaScript
- Errors and Debugging
- Online Resources
- Wrapping Up
- Part 2: JavaScript Fundamentals
- Chapter 4: Simple Variable Types
- Basics of Variables
- Working with Numbers
- Working with Strings
- Performing Type Conversions
- Review and Pursue
- Wrapping Up
- Chapter 5: Using Control Structures
- Basics of Conditionals
- More Conditionals
- More Complex Conditions
- Basics of Loops
- Review and Purse
- Wrapping Up
- Chapter 6: Complex Variable Types
- Generating Dates and Times
- Working with Arrays
- Workings with Objects
- Arrays versus Objects
- Review and Purse
- Wrapping Up
- Chapter 7: Creating Functions
- The Fundamentals
- Functions as Objects
- The Fancier Stuff
- Review and Purse
- Wrapping Up
- Chapter 8: Event Handling
- The Premise of Event Handling
- Creating Event Listeners
- Creating a Utility Library
- Event Types
- Event Accessibility
- Events and Progressive Enhancement
- Advanced Event Handling
- Review and Purse
- Wrapping Up
- Chapter 9: JavaScript and the Browser
- Using Dialog Windows
- Working with the Window
- Manipulating the DOM
- JavaScript and CSS
- Working with Cookies
- Using Timers
- Review and Purse
- Wrapping Up
- Chapter 10: Working with Forms
- General Form Considerations
- Text Inputs and Textareas
- Select Menus
- Checkboxes
- Radio Buttons
- Handling File Uploads
- Regular Expressions
- Putting It All Together
- Review and Purse
- Wrapping Up
- Chapter 11: Ajax
- Ajax Basics
- Working with Other Data
- The Server-Side Script
- Ajax Examples
- Review and Purse
- Wrapping Up
- Chapter 12: Error Management
- Catching and Throwing Errors
- Using Assertions
- Unit Testing
- Review and Purse
- Wrapping Up
- Part 3: Next Steps
- Chapter 13: Frameworks
- Choosing a Framework
- Introducing jQuery
- Introducing YUI
- Libraries
- Review and Purse
- Wrapping Up
- Chapter 14: Advanced JavaScript
- Defining Namespaces
- Creating Custom Objects
- Understanding Prototypes
- Working with Closures
- Alternative Type Identification
- Minifying Code
- Review and Purse
- Wrapping Up
- Chapter 15: PHP and JavaScript Together
- Identifying the Goal
- Creating the Database
- Establishing the Site
- Coding the Non-JavaScript Version
- Creating the Ajax Resources
- Adding the JavaScript
- Completing This Example
- Review and Purse
- Wrapping Up
- Index
Stefanov, S. (2008 ) Object-Oriented JavaScript: Create scalable, reusable high-quality JavaScript applications and libraries, Packt Publishing
A newer edition of this book is available
Create scalable and reusable high-quality JavaScript applications and libraries using the concepts of object-oriented programming. This book is for the beginning to intermediate web developer who wants to solve web development problems with smart JavaScript. It does not assume any prior knowledge of JavaScript programming; however even if you already know some JavaScript, there will be plenty for you to learn here.
This book teaches JavaScript as an object-oriented language of immense versatility. With the coding know-how contained here you’ll have a lot more power to your programmer’s elbow. For beginners or intermediates.
Once listed in the “nice to have” sections of job postings, these days the knowledge of JavaScript is a deciding factor when it comes to hiring web developers. And rightly so. Where in the past we used to have the occasional few lines of JavaScript embedded in a web page, now we have advanced libraries and extensible architectures, powering the “fat-client”, AJAX-type rich internet applications.
JavaScript is the language of the browser, but it’s also heavily employed in many other environments: server-side programming, desktop applications, application extensions and widgets. It’s a pretty good deal: you learn one language and then code all kinds of different applications. While this book has one chapter specifically dedicated to the web browser environment including DOM, events, and AJAX tutorials, the rest is applicable to all the other environments too.
This book treats JavaScript as a serious object-oriented language, showing you how to build robust, maintainable, and powerful libraries and applications. Along the way, we cover many of the recent innovations such as AJAX, JSON, and interesting design and coding patterns. After reading this book, you’ll be prepared to ace your JavaScript job interview and even impress with some bits that the interviewer maybe didn’t know. You should read this book if you want to be able to take your JavaScript skills to a new level of sophistication.
What You Will Learn
- Learn to think in JavaScript, the language of the web browser
- The basics of object-oriented programming, and how they apply to JavaScript
- Set up and use your training environment (Firebug)
- Master data types, operators, and flow control statements
- Understand functions: usage patterns, variable scope, and built-in functions
- Closures demystified
- Create and use objects
- Understand and use prototypes
- Reuse code with common patterns for inheritance
- Understand and work with the BOM (Browser Object Model)
- The DOM (Document Object Model) – accessing, modifying, adding, and deleting nodes
- Build responsive web pages with AJAX
- JSON (JavaScript Object Notation)
- Listen and respond to browser events
- Apply design patterns to solve common problems
- Adopt coding patterns that unleash the unique power of the language
- Make your programs cleaner, faster, and compatible with other programs and libraries
- Achieve missing object-oriented features in JavaScript such as private properties and methods
Table of Contents
Wright, T. (2013) Learning JavaScript: A Hands-On Guide to the Fundamentals of Modern JavaScript, Addison-Wesley, Pearson Education , Inc.
Download eBook PDF (PDF 6,887KB)
Companion Web Site: http://learningjsbook.com/
Get Started Fast with Modern JavaScript Web Development! With the arrival of HTML5, jQuery, and Ajax, JavaScript web development skills are more valuable than ever! This complete, hands-on JavaScript tutorial covers everything you need to know now. Using line-by-line code walkthroughs and end-of-chapter exercises, top web developer and speaker Tim Wright will help you get results fast, even if you’ve never written a line of JavaScript before. Smart, friendly, enthusiastic, and packed with modern examples, Learning JavaScript covers both design-level and development-level JavaScript. You’ll find expert knowledge and best practices for everything from jQuery and interface design to code organization and front-end templating. Wright’s focused coverage includes regular break points and clear reviews that make modern JavaScript easier to learn—and easier to use! Learning JavaScript is your fastest route to success with JavaScript—whether you’re entirely new to the language or you need to sharpen and upgrade skills you first learned a decade ago! Coverage includes • Mastering all of the JavaScript concepts and terminology you need to write new programs or efficiently modify existing code • Creating robust, secure code for both the design and development levels • Maximizing usability, reusability, accessibility, clarity, security, and performance • Taking full advantage of the browser environments your code will run in • Accessing the DOM to create behaviors and data interactions • Storing data for easy and efficient access • Using variables, functions, loops, and other core language features • Interacting with users through events • Communicating with servers through Ajax • Improving your productivity with JavaScript libraries.
Table of Contents
I>Chapter 1: Progressive Enhancement 3
Defining Progressive Enhancement 3
History 4
Purpose 5
Accessibility 5
Reusability 5
Progressive Enhancement Versus Graceful
Degradation 6
Structure Layer 6
Adding More Meaning with HTML5 8
Presentation Layer 9
Inline CSS 10
Linking Up Your Stylesheet 10
Behavior Layer 12
Inline JavaScript 12
Embedded JavaScript 13
External and Unobtrusive JavaScript 15
Benefits of Progressive Enhancement 16
Performance 17
Building for the Future 17
The Touch Interface 18
Final Words on Progressive Enhancement 19
Summary 20
Exercises 20
Chapter 2: JavaScript in the Browser 21
A People’s History of JavaScript 21
Origins 22
Progressive Enhancement 23
The Behavior Layer 24
Moving Past Today 24
Browser Interactions with JavaScript 25
HTTP Requests 26
JavaScript and Rendering Engines 29
What JavaScript Can Do 30
Modifying HTML 31
Communicating with the Server 31
Storing Data 31
How You Should Use JavaScript 32
Improving User Experience 32
Using JavaScript Responsibly 32
Creating Fallbacks 34
Tools to Help You Use JavaScript 36
Tools Built into the Language 36
Tools Built into the Browser 37
Summary 38
Exercises 38
Chapter 3: JavaScript Terminology 39
Basics 39
Document Object Model (DOM) 39
Parents 40
Children 40
Siblings 41
Variables 41
Strings 43
Comments 43
Operators 44
Use Strict 45
Storage 45
Cache 45
Arrays 45
Cookies 46
JavaScript Object Notation (JSON) 46
Objects 47
Creating Interaction 47
Loops 48
Conditionals 48
switch Statement 49
Functions 50
Anonymous Functions 51
Callback Functions 52
Methods 53
Events 54
Ajax 54
Summary 55
Exercises 55
Chapter 4: Accessing the DOM 57
What Is the DOM? 57
The DOM Tree 58
Element Nodes 59
Text Nodes 60
Attribute Nodes 62
Working with the Element Node 62
Targeting by ID 63
Targeting by Tag Name 64
Targeting by Class 67
Using CSS Selectors in JavaScript to Target Nodes 68
Working with the Attribute Node 70
Getting an Attribute 71
Setting an Attribute 72
Removing an Attribute 73
Working with the Text Node and Changing Content 73
Moving Around the DOM 74
Accessing First and Last Child 76
Dynamically Adding and Removing Nodes from the
DOM 77
Adding Elements to the DOM 77
Removing Elements from the DOM 78
Summary 79
Exercises 79
Chapter 5: Storing Data in JavaScript 81
Variables 81
Strings 82
Numbers 83
Boolean 84
Performance in Variables 84
Arrays 85
Basic Array 85
Associative Array 87
Multidimensional Array 87
Pushing Data into an Array 89
Working with Array Methods 89
join 90
slice 90
shift and unshift 91
pop 92
concat 92
sort 93
Objects 93
Performance in Objects 94
JSON 95
Benefits of Using JSON 96
Using an API 96
Web Storage in HTML5 97
localStorage and sessionStorage 97
setItem 97
getItem 98
removeItem 98
Storing Chunks of Data with JSON 99
Using Web Storage Responsibly 100
Summary 101
Exercises 101
Chapter 6: Variables, Functions, and Loops 103
Defining Variables 103
Grouping Variables 104
Reserved Terms 104
Functions 105
Basic Functions 106
Anonymous Functions 107
Scope 108
Calling a Function with a Function 109
Returning Data 110
A Function as a Method 112
Loops 113
for Loop 114
Conditionals 116
if Statement 116
if/else Statement 117
switch Statement 118
if versus switch 119
Putting It All Together 120
Summary 121
Exercises 122
Chapter 7: Interacting with the User Through Events 123
Attaching an Event 124
Event Handlers 124
Event Listeners 125
Binding Events 128
Unbinding Events 129
Mouse and Keyboard Events 130
click 132
focus and blur 134
Accessibility 135
change 135
mouseover and mouseout (hovering) 136
submit 137
Preventing Default Behavior 139
keydown, keypress, and keyup 139
Putting It All Together 140
Touch and Orientation Events 143
touchstart and touchend 144
touchmove 145
orientationchange 145
Support for Touch Events 146
Putting It All Together 147
Summary 148
Exercises 148
Chapter 8: Communicating with the Server Through
Ajax 149
Ajax History 150
Server Communication 151
The XMLHttpRequest 152
Creating an Ajax Call 154
Sending a Request to the Server 155
Receiving Data Back from the Server 158
Making Repeat Ajax Calls 163
Ajax Data Formats 164
XML 165
HTML 166
JSON 167
Ajax Accessibility 168
Live Regions and ARIA 169
Common Ajax Mistakes 170
Providing Feedback 170
Putting It All Together 172
Where Is Ajax Going? 177
Summary 177
Exercises 178
Chapter 9: Code Organization 179
General Coding Style Rules 180
Scope 181
Failing Quickly 183
User Experience 185
Code Design 185
Files and Directories 186
In-document Script 187
Variable Declarations 188
Variable and Function Naming 189
Comments 190
Indentation 192
Whitespace 193
Statement Spacing 194
Line Breaks 195
Math and Operators 196
Using eval() 197
Taking Style Guides Too Far 199
Code Structure 200
Functions 200
Anonymous Functions 201
Functions as Variables 202
Functions as Methods 202
JavaScript Development Patterns 204
Summary 208
Exercises 209
Chapter 10: Making JavaScript Easier with Libraries 211
JavaScript Library Basics 212
The Library Learning Process 213
Syntax 214
Focusing on the Goal 214
Creating Shortcuts 215
Fixing Browser Issues 216
Popular Libraries 216
jQuery Basics 221
document.ready 222
Selectors 223
Traveling Through the DOM 225
Adding Style Information 226
Binding Events 227
Animation 227
jQuery Nonbasics 228
Using Ajax in jQuery 228
Looping Through Data in jQuery 230
Chaining Functions 232
Extending Libraries Through Plug-ins 233
Building a Plug-in 234
The Good of Libraries 236
Popularity and Community 236
Efficient Code 237
The Bad of Libraries 238
Overhead 238
Performance 239
Overreliance and Shelf Life 239
Using Microlibraries 240
The Good 240
The Bad 241
Summary 242
Exercises 242
Chapter 11: HTML5 JavaScript APIs 243
What Is HTML5? 244
The Markup (aka HTML) 244
Creating Better Semantics 245
Building More Accessible Content 245
The JavaScript APIs 248
The navigator Object 248
Geolocation 249
Audio and Video 251
History API 254
Web Workers 259
Device API 265
The Battery Status API 266
The Vibration API 267
The Network Information API 268
Using This Today with Feature Detection 270
Summary 271
Exercises 272
Chapter 12: Moving Forward with JavaScript 273
A Brief Review of Key Topics 274
Progressive Enhancement 274
DOM Manipulation 275
Data Storage 277
Server Communication 279
JavaScript for Designers 279
Advanced Interface Design 280
CSS Transforms in JavaScript 284
Interacting from the Desktop 289
JavaScript for Developers 293
JavaScript Templates 294
JavaScript on the Server with NodeJS 299
Summary 302
Exercises 303
Answers 305
Index 309
Negrino, T. and Smith, Dori (2012) JavaScript, Visual QuickStart Guide, Eighth Edition, PeachPit Press
There is a newer edition of this book.
Download eBook PDF (PDF 20,997KB)
Download Source Code (ZIP 1,350KB)
This task-based, visual-reference guide has been fully revised and uses step-by-step instructions and plenty of screenshots to give beginning and intermediate scripters what they need to know to keep their skills up-to-date. Readers can start from the beginning to get a tour of the programming language, or look up specific tasks to learn just what they need to know. In this updated eighth edition, readers will find new information on using frameworks and libraries–such as jQuery–and modern coding techniques.
Table of Contents
Introduction
Chapter 1: Getting Acquainted with JavaScript
Chapter 2: Start Me Up!
Chapter 3: Your First Web App
Chapter 4: Working with Images
Chapter 5: Windows and Frames
Chapter 6: Form Handling
Chapter 7: Forms and Regular Expressions
Chapter 8: Handling Events
Chapter 9: JavaScript and Cookies
Chapter 10: Objects and the DOM
Chapter 11: Making Your Pages Dynamic
Chapter 12: Applied JavaScript
Chapter 13: Introducing Ajax
Chapter 14: Frameworks, Libraries, and Toolkits
Chapter 15: Designing with jQuery
Chapter 16: jQuery and Ajax
Chapter 17: Bookmarklets
Appendix A: JavaScript Genealogy and Reference
Appendix B: JavaScript Reserved Words
Appendix C: Where to Learn More
Vander Veer, E. (2005) JavaScript for Dummies, Fourth Edition, Wiley Publishing, Inc.
Download Source Code (ZIP 271KB)
Responding to reader feedback, the author has thoroughly revamped the book with more step-by-step coverage of JavaScript basics, an exclusive focus on Internet Explorer, and many complete sample scripts, Updated to cover JavaScript 1.5, the latest release of this popular Web scripting language. Using lots of examples, including a sample working Web site, the book shows how to create dynamic and interactive pages, build entire sites, and automate pages
Haverbeke, M. (2011) Eloquent JavaScript: A Modern Introduction to Programming, No Starch Press, Inc.
Download eBook PDF (PDF 2,808KB)
“A concise and balanced mix of principles and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript!”—Brendan Eich, creator of JavaScript
JavaScript is the language of the Web, and it’s at the heart of every modern website from the lowliest personal blog to the mighty Google Apps. Though it’s simple for beginners to pick up and play with, JavaScript is not a toy—it’s a flexible and complex language, capable of much more than the showy tricks most programmers use it for.
Eloquent JavaScript goes beyond the cut-and-paste scripts of the recipe books and teaches you to write code that’s elegant and effective. You’ll start with the basics of programming, and learn to use variables, control structures, functions, and data structures. Then you’ll dive into the real JavaScript artistry: higher-order functions, closures, and object-oriented programming.
Along the way you’ll learn to:
- Master basic programming techniques and best practices
- Harness the power of functional and object-oriented programming
- Use regular expressions to quickly parse and manipulate strings
- Gracefully deal with errors and browser incompatibilities
- Handle browser events and alter the DOM structure
Most importantly, Eloquent JavaScript will teach you to express yourself in code with precision and beauty. After all, great programming is an art, not a science—so why settle for a killer app when you can create a masterpiece?
Companion Web Site: http://eloquentjavascript.net/
Eloquent JavaScript
Second edition
Contents
- Introduction
-
(Part 1: Language)
- Program Structure
- Functions
- Data Structures: Objects and Arrays
- Higher-order Functions
- The Secret Life of Objects
- Project: Electronic Life
- Bugs and Error Handling
- Regular Expressions
- Modules
- Project: A Programming Language
-
(Part 2: Browser)
- The Document Object Model
- Handling Events
- Project: A Platform Game
- Drawing on Canvas
- HTTP
- Forms and Form Fields
- Project: A Paint Program
-
(Part 3: Node)
- Project: Skill-Sharing Website
Other pages
A paper version of Eloquent JavaScript, including a bonus chapter, is being brought out by No Starch Press. They also sell an ebook version more polished than the files linked below.
- Code sandbox and exercise solutions
- Errata for the paper book
- This book as a single PDF file (& small version for mobile)
- This book as an EPUB file
- This book as a MOBI (Kindle) file
- The first edition of the book