JavaScript in 24 Hours, Sams Teach Yourself, Sixth Edition

Book description

Sams Teach Yourself JavaScript in 24 Hours, Sixth Edition

New coverage of ECMAScript 6

In just 24 lessons of one hour or less, Sams Teach Yourself JavaScript in 24 Hours helps you learn the fundamentals of programming using the JavaScript language.

Designed for beginners with no previous programming experience, this book’s straightforward, step-by-step approach shows you how to use JavaScript to add a wide array of interactive features and effects to your web pages.

Every lesson builds on what you’ve already learned, giving you a rock-solid foundation for real-world success.

Step-by-step instructions carefully walk you through the most common JavaScript programming tasks.

Practical, hands-on examples show you how to apply what you learn.

Quizzes and exercises help you test your knowledge and stretch your skills.

Notes and tips point out shortcuts and solutions.

Upgrade to the online Learning Lab edition of this book for just $10 with purchase. See inside for details.

Learn how to…

·         Use JavaScript to build dynamic, interactive web pages

·         Debug scripts

·         Create scripts that work in all browsers

·         Write clear, reliable, and reusable code

·         Use object-oriented programming techniques

·         Script with the DOM

·         Access JSON data

·         Work with HTML5 and CSS3

·         Leverage the popular jQuery library

·         Control CSS with simple JavaScripts

·         Read and write cookies

·         Use some of the new ECMAScript features today

·         Get started with frameworks such as AngularJS

·         Build browser add-ons and extensions

Register your book at informit.com/register for convenient access to updates, downloads, and corrections as they become available.

Who This Book Is For

  • Those who have at least a basic understanding of HTML and web page design in general and want to move on to adding some extra interactivity to your pages. 

  • Those who currently code in another programming language and want to see what additional capabilities JavaScript can add to your armory

  • Someone who has never done any computer programming. Browse through an HTML primer before using this book. You don't need to be an HTML expert to use JavaScript but should have a basic understanding.

  • Table of contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Contents at a Glance
    5. Table of Contents
    6. About the Author
    7. We Want to Hear from You!
    8. Reader Services
    9. Introduction
      1. Who This Book Is For
      2. The Aims of This Book
      3. Conventions Used
      4. Q&A, Workshop, and Exercises
      5. How the Book Is Organized
      6. Tools You’ll Need
    10. Part I: First Steps with JavaScript
      1. Hour 1. Introducing JavaScript
        1. Web Scripting Fundamentals
        2. Server- Versus Client-Side Programming
        3. JavaScript in a Nutshell
        4. Where JavaScript Came From
          1. The Browser Wars
        5. The <script> Tag
        6. Introducing the DOM
          1. The W3C and Standards Compliance
          2. The window and document Objects
          3. Object Notation
        7. Talking to the User
          1. window.alert()
          2. document.write()
          3. Reading a Property of the document Object
        8. Summary
        9. Q&A
        10. Workshop
          1. Quiz
          2. Answers
        11. Exercises
      2. Hour 2. Writing Simple Scripts
        1. Including JavaScript in Your Web Page
        2. JavaScript Statements
          1. Commenting Your Code
        3. Variables
        4. Operators
          1. Arithmetic Operations
          2. Operator Precedence
          3. Using the + Operator with Strings
        5. Capturing Mouse Events
          1. The onClick Event Handler
          2. onMouseOver and onMouseOut Event Handlers
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
        9. Exercises
      3. Hour 3. Using Functions
        1. General Syntax
        2. Calling Functions
          1. Putting JavaScript Code in the Page <head>
        3. Passing Arguments to Functions
          1. Multiple Arguments
        4. Returning Values from Functions
        5. Scope of Variables
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
        9. Exercises
      4. Hour 4. DOM Objects and Built-in Objects
        1. Interacting with the User
          1. alert()
          2. confirm()
          3. prompt()
        2. Selecting Elements by Their ID
          1. The innerHTML Property
        3. Accessing Browser History
        4. Using the location Object
          1. Navigating Using the location Object
          2. Reloading the Page
        5. Browser Information—The navigator Object
        6. Dates and Times
          1. Create a Date Object with the Current Date and Time
          2. Creating a Date Object with a Given Date and Time
          3. Setting and Editing Dates and Times
        7. Simplifying Calculation with the Math Object
          1. Rounding
          2. Finding Minimum and Maximum
          3. Random Numbers
          4. Mathematical Constants
          5. The with Keyword
        8. Summary
        9. Q&A
        10. Workshop
          1. Quiz
          2. Answers
        11. Exercises
    11. Part II: Cooking with Code
      1. Hour 5. Numbers and Strings
        1. Numbers
          1. Integers
          2. Floating-Point Numbers
          3. Not a Number (NaN)
          4. Using parseFloat() and parseInt()
          5. Infinity
        2. Strings
          1. Escape Sequences
          2. String Methods
        3. Boolean Values
          1. The Negation Operator (!)
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
        7. Exercises
      2. Hour 6. Arrays
        1. Arrays
          1. Creating a New Array
          2. Initializing an Array
          3. Array Methods
        2. Summary
        3. Q&A
        4. Workshop
          1. Quiz
          2. Answers
        5. Exercise
      3. Hour 7. Program Control
        1. Conditional Statements
          1. The if() Statement
          2. Comparison Operators
          3. Testing for Equality
          4. More about if()
          5. Testing Multiple Conditions
          6. The switch Statement
          7. Logical Operators
        2. Loops and Control Structures
          1. while
          2. do ... while
          3. for
          4. Leaving a Loop with break
          5. Looping Through Objects with for ... in
        3. Setting and Using Timers
          1. setTimeout()
          2. setInterval()
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
        7. Exercises
    12. Part III: Objects
      1. Hour 8. Object-Oriented Programming
        1. What Is Object-Oriented Programming?
        2. Object Creation
          1. Create a Direct Instance
          2. Anonymous Functions
          3. Using a Constructor Function
        3. Extending and Inheriting Objects Using prototype
          1. Extending Objects
          2. Inheritance
        4. Encapsulation
        5. Using Feature Detection
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
        9. Exercises
      2. Hour 9. Scripting with the DOM
        1. DOM Nodes
          1. Types of Nodes
          2. The childNodes Property
          3. firstChild and lastChild
          4. The parentNode Property
          5. nextSibling and previousSibling
          6. Node Value
          7. Node Name
        2. Selecting Elements with getElementsByTagName()
        3. Reading an Element’s Attributes
        4. Mozilla’s DOM Inspector
          1. Creating New Nodes
          2. Manipulating Child Nodes
          3. appendChild()
          4. insertBefore()
          5. replaceChild()
          6. removeChild()
          7. Editing Element Attributes
          8. Dynamically Loading JavaScript Files
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
        8. Exercises
      3. Hour 10. Meet JSON
        1. What Is JSON?
          1. JSON Syntax
        2. Accessing JSON Data
          1. Using eval()
          2. Using Native Browser Support
        3. Data Serialization with JSON
          1. JSON.stringify()
        4. JSON Data Types
        5. Simulating Associative Arrays
        6. Creating Objects with JSON
          1. Properties
          2. Methods
          3. Arrays
          4. Objects
        7. JSON Security
        8. Summary
        9. Q&A
        10. Workshop
          1. Quiz
          2. Answers
        11. Exercises
    13. Part IV: HTML and CSS
      1. Hour 11. JavaScript and HTML5
        1. New Markup for HTML5
        2. Some Important New Elements
          1. Video Playback with <video>
          2. Testing Format Support with canPlayType()
          3. Controlling Playback
          4. Playing Sound with the <audio> Tag
          5. Drawing on the Page with <canvas>
        3. Drag and Drop
        4. Local Storage
        5. Working with Local Files
          1. Checking for Browser Support
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
        9. Exercises
      2. Hour 12. JavaScript and CSS
        1. A Ten-Minute CSS Primer
          1. Separating Style from Content
          2. CSS Style Declarations
          3. Where to Place Style Declarations
        2. The DOM style Property
        3. Accessing Classes Using className
        4. The DOM styleSheets Object
          1. Enabling, Disabling, and Switching Stylesheets
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
        8. Exercises
      3. Hour 13. Introducing CSS3
        1. Vendor-Specific Properties and Prefixes
        2. CSS3 Borders
          1. Create Box Shadows
          2. Rounding Corners with the border-radius property
        3. CSS3 Backgrounds
          1. The background-size Property
          2. The background-origin Property
          3. Multiple Background Images
        4. CSS3 Gradients
          1. Linear Gradients
          2. Radial Gradients
        5. CSS3 Text Effects
          1. Text Shadow
          2. Word Wrap
        6. CSS3 Transitions, Transformations, and Animations
        7. Referencing CSS3 Properties in JavaScript
          1. Converting CSS Property Names to JavaScript
          2. The DOM getComputedStyle() Method
        8. Setting CSS3 Properties with Vendor Prefixes
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
        12. Exercises
    14. Part V: Using JavaScript Libraries
      1. Hour 14. Using Libraries
        1. Why Use a Library?
        2. What Sorts of Things Can Libraries Do?
        3. Some Popular Libraries
          1. Prototype Framework
          2. Dojo
          3. The Yahoo! UI Library
          4. MooTools
          5. jQuery
        4. Introducing prototype.js
          1. The $() Function
          2. The $F() Function
          3. The Form Object
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
        8. Exercises
      2. Hour 15. A Closer Look at jQuery
        1. Including jQuery in Your Pages
          1. Download jQuery
          2. Use a Remote Version
        2. jQuery’s $(document).ready Handler
        3. Selecting Page Elements
        4. Working with HTML Content
          1. html()
          2. text()
          3. attr()
        5. Showing and Hiding Elements
          1. show()
          2. hide()
          3. toggle()
        6. Animating Elements
          1. Fading
          2. Sliding
          3. Animation
        7. Command Chaining
        8. Handling Events
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
        12. Exercises
      3. Hour 16. The jQuery UI User Interface Library
        1. What jQuery UI Is All About
        2. How to Include jQuery UI in Your Pages
          1. Using the ThemeRoller
        3. Interactions
          1. Drag and Drop
          2. Resize
          3. Sort
        4. Using Widgets
          1. Accordion
          2. Date Picker
          3. Tabs
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
        8. Exercises
      4. Hour 17. Ajax with jQuery
        1. The Anatomy of Ajax
          1. Introducing Ajax
          2. The XMLHttpRequest Object
          3. Different Rules for Different Browsers
          4. Methods and Properties
          5. Talking with the Server
          6. What Happens at the Server?
          7. Dealing with the Server Response
          8. But There’s an Easier Way, Right?
        2. Using jQuery to Implement Ajax
          1. load()
          2. get() and post()
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
        6. Exercises
    15. Part VI: Advanced Topics
      1. Hour 18. Reading and Writing Cookies
        1. What Are Cookies?
          1. Limitations of Cookies
        2. The document.cookie Property
          1. Escaping and Unescaping Data
        3. Cookie Ingredients
          1. cookieName and cookieValue
          2. domain
        4. Writing a Cookie
        5. A Function to Write a Cookie
        6. Reading a Cookie
        7. Deleting Cookies
        8. Setting Multiple Values in a Single Cookie
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
        12. Exercises
      2. Hour 19. Coming Soon to JavaScript
        1. Classes
        2. Arrow Functions
        3. Modules
        4. Using let and const
        5. Template Strings
        6. Access Arrays with for-of
        7. Transpilation
        8. Summary
        9. Q&A
        10. Workshop
          1. Quiz
          2. Answers
        11. Exercises
      3. Hour 20. Using Frameworks
        1. Software Frameworks
          1. Why Use a Framework?
          2. Frameworks Are Not the Same as Libraries
        2. Model-View-Controller (MVC) Architecture
          1. Models
          2. Views
          3. Controllers
        3. Using an MVC Framework for Web Apps
        4. The AngularJS Framework
          1. An Overview of AngularJS
          2. Including AngularJS in your page
          3. Extending HTML with ng- directives
          4. Scopes
          5. Directives
          6. Filters
        5. Building an AngularJS Application
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
        9. Exercises
      4. Hour 21. JavaScript Beyond the Web Page
        1. JavaScript Outside the Browser
        2. Writing Google Chrome Extensions
          1. Building a Simple Extension
          2. Debugging the Extension
        3. Going Further
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
        7. Exercises
    16. Part VII: Learning the Trade
      1. Hour 22. Good Coding Practice
        1. Don’t Overuse JavaScript
        2. Writing Readable and Maintainable Code
          1. Use Comments Sensibly
          2. Choose Helpful File, Property, and Method Names
          3. Reuse Code Where You Can
          4. Don’t Assume
        3. Graceful Degradation
        4. Progressive Enhancement
          1. Separate Style, Content, and Code
        5. Unobtrusive JavaScript
          1. Leave That HTML Alone
          2. Use JavaScript Only as an Enhancement
        6. Feature Detection
        7. Handling Errors Well
          1. Using try and catch
        8. Summary
        9. Q&A
        10. Workshop
          1. Quiz
          2. Answers
        11. Exercises
      2. Hour 23. Debugging Your Code
        1. An Introduction to Debugging
          1. Types of Errors
          2. Choosing a Programmer’s Editor
          3. Simple Debugging with alert()
        2. More Advanced Debugging
          1. The Console
          2. Grouping Messages
          3. Using Breakpoints to Halt Code Execution
          4. Conditional Breakpoints
          5. Launching the Debugger from Your Code
          6. Watch Expressions
          7. Validating JavaScript
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
        6. Exercises
      3. Hour 24. JavaScript Unit Testing
        1. What Is Unit Testing?
        2. Writing JavaScript for Unit Testing
          1. Refactoring Code
        3. The QUnit Test Suite
          1. Installing QUnit
          2. A Minimal QUnit Setup
          3. Retesting Our addTax() Function
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
        7. Exercises
    17. Part IX: Appendices
      1. Appendix A. Tools for JavaScript Development
        1. Editors
          1. Notepad++
          2. jEdit
          3. SciTE
          4. Geany
        2. Validators
          1. The W3C Validation Services
          2. Web Design Group (WDG)
        3. Debugging and Verifying Tools
          1. Firebug
          2. JSLint
      2. Appendix B. JavaScript Quick Reference
    18. Index
    19. Code Snippets

    Product information

    • Title: JavaScript in 24 Hours, Sams Teach Yourself, Sixth Edition
    • Author(s): Phil Ballard
    • Release date: June 2015
    • Publisher(s): Sams
    • ISBN: 9780134172163