JavaScript: A Beginner's Guide, Fifth Edition, 5th Edition

Book description

Publisher's Note: Products purchased from Third Party sellers are not guaranteed by the publisher for quality, authenticity, or access to any online entitlements included with the product.


Get up and running on the latest JavaScript standard using this fully updated beginner’s guide

This hands-on, fast-paced guide shows, from start to finish, how to create dynamic Web pages complete with special effects using JavaScript. This edition contains updates for all major new features and the latest Web development techniques and practices. You will discover how to extend JavaScript’s capabilities to the server side using Node.js.

JavaScript: A Beginner's Guide, Fifth Edition begins by clearly explaining the fundamentals, including variables, functions, operators, event handlers, objects, arrays, strings, and forms. From there, the book moves on to more advanced techniques, such as debugging, accessibility, and security. Throughout, “Ask the Expert,” “Try This,” notes, tips, and self tests highlight salient points and aid in learning.

•Teaches, step by step, how to get started developing Web applications
•Features detailed examples and downloadable project files
•Written by an experienced Web developer and JavaScript expert

Table of contents

  1. Cover
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. Contents
  6. ACKNOWLEDGMENTS
  7. INTRODUCTION
  8. 1 Introduction to JavaScript
    1. What You Need to Know
      1. Basic HTML and CSS Knowledge
      2. Basic Text Editor and Web Browser Knowledge
      3. Which Version?
      4. Client-Side and Server-Side Programming
    2. Beginning with JavaScript
      1. Prototype-Based
      2. Interpreted Language
      3. Numerous Environments
    3. Putting It All Together
    4. Online Resources
    5. Try This 1-1: Use JavaScript to Write Text
    6. Chapter 1 Self Test
  9. 2 Placing JavaScript in an HTML File
    1. Using the HTML Script Tags
      1. Identifying the Scripting Language
      2. Calling External Scripts
      3. Specifying when the Script Should Load
      4. Using <noscript></noscript> Tags
    2. Creating Your First Script
      1. Writing a “Hello World” Script
      2. Creating an HTML Document for the Script
      3. Inserting the Script into the HTML Document
    3. Try This 2-1: Insert a Script into an HTML Document
    4. Using External JavaScript Files
      1. Creating a JavaScript File
      2. Creating the HTML Files
      3. Viewing the Pages in Your Browser
    5. Try This 2-2: Call an External Script from an HTML Document
    6. Using JavaScript Comments
      1. Inserting Comments on One Line
      2. Adding Multiple-Line Comments
    7. Chapter 2 Self Test
  10. 3 Using Variables
    1. Understanding Variables
    2. Why Variables Are Useful
      1. Variables as Placeholders for Unknown Values
      2. Variables as Time-Savers
      3. Variables as Code Clarifiers
    3. Defining Variables for Your Scripts
      1. Declaring Variables
      2. Assigning Values to Variables
      3. Naming Variables
    4. Understanding Data Types
      1. Number
      2. String
      3. Boolean
      4. Null
      5. Undefined
      6. Symbol
      7. Object
    5. Try This 3-1: Declare Variables
    6. Using Variables in Scripts
      1. Making a Call to a Variable
      2. Adding Variables to Text Strings
    7. Writing a Page of JavaScript
      1. Creating the Framework
      2. Defining the Variables
      3. Adding the Commands
      4. Modifying the Page
    8. Try This 3-2: Create an HTML Page with JavaScript
    9. Chapter 3 Self Test
  11. 4 Using Functions
    1. What a Function Is
    2. Why Functions Are Useful
    3. Structuring Functions
      1. Declaring Functions
      2. Defining the Code for Functions
      3. Naming Functions
      4. Adding Arguments to Functions
      5. Adding Return Statements to Functions
    4. Calling Functions in Your Scripts
      1. Script Tags: Head Section or Body Section
      2. Calling a Function from Another Function
      3. Calling Functions with Arguments
      4. Calling Functions with Return Statements
      5. Other Ways to Define Functions
    5. Try This 4-1: Create an HTML Page with Functions
    6. Scope/Context Basics
      1. Global Context
      2. Function Context
      3. Block Context
    7. Try This 4-2: Write Your Own Functions
    8. Chapter 4 Self Test
  12. 5 JavaScript Operators
    1. Understanding the Operator Types
    2. Understanding Arithmetic Operators
      1. The Addition Operator (+)
      2. The Subtraction Operator (–)
      3. The Multiplication Operator (*)
      4. The Division Operator (/)
      5. The Modulus Operator (%)
      6. The Increment Operator (++)
      7. The Decrement Operator (– –)
      8. The Unary Plus Operator (+)
      9. The Unary Negation Operator (–)
      10. The Exponentiation Operator
    3. Understanding Assignment Operators
      1. The Assignment Operator (=)
      2. The Add-and-Assign Operator (+=)
      3. The Subtract-and-Assign Operator (–=)
      4. The Multiply-and-Assign Operator (*=)
      5. The Divide-and-Assign Operator (/=)
      6. The Modulus-and-Assign Operator (%=)
      7. The Exponent-and-Assign Operator (**=)
    4. Try This 5-1: Adjust a Variable Value
    5. Understanding Comparison Operators
      1. The Is-Equal-To Operator (==)
      2. The Is-Not-Equal-To Operator (!=)
      3. The Strict Is-Equal-To Operator (===)
      4. The Strict Is-Not-Equal-To Operator (!==)
      5. The Is-Greater-Than Operator (>)
      6. The Is-Less-Than Operator (<)
      7. The Is-Greater-Than-or-Equal-To Operator (>=)
      8. The Is-Less-Than-or-Equal-To Operator (<=)
    6. Understanding Logical Operators
      1. The AND Operator (&&)
      2. The OR Operator (||)
      3. The NOT Operator (!)
      4. The Bitwise Operators
    7. Special Operators
    8. Understanding Order of Operations
    9. Try This 5-2: True or False?
    10. Chapter 5 Self Test
  13. 6 Conditional Statements and Loops
    1. Defining Conditional Statements
      1. What Is a Conditional Statement?
      2. Why Conditional Statements Are Useful
    2. Using Conditional Statements
      1. Using if/else Statements
      2. Using the switch Statement
      3. Using the Conditional Operator
      4. User Input from a Prompt
    3. Try This 6-1: Work with User Input
    4. Defining Loops
      1. What Is a Loop?
      2. Why Loops Are Useful
    5. Using Loops
      1. for
      2. while
      3. do while
      4. for in, for each in, and for of
      5. Using break and continue
    6. Try This 6-2: Work with for Loops and while Loops
    7. Chapter 6 Self Test
  14. 7 JavaScript Arrays
    1. What Is an Array?
    2. Why Arrays Are Useful
    3. Defining and Accessing Arrays
      1. Naming an Array
      2. Defining an Array
      3. Accessing an Array’s Elements
      4. Using the length Property and Loops
      5. Changing Array Values and Changing the Length
    4. Try This 7-1: Use Loops with Arrays
    5. Array Properties and Methods
      1. Properties
      2. Methods
    6. Nesting Arrays
      1. Defining Nested Arrays
      2. Loops and Nested Arrays
    7. Try This 7-2: Nested Arrays Practice
    8. Chapter 7 Self Test
  15. 8 Objects
    1. Defining Objects
    2. Creating Objects
      1. Naming
      2. Single Objects
    3. Try This 8-1: Create a Computer Object
    4. Object Structures
      1. Constructor Functions
      2. Using Prototypes
      3. The class Keyword
    5. Helpful Statements for Objects
      1. The for-in Loop
      2. The with Statement
    6. Try This 8-2: Practice with the Combination Constructor/Prototype Pattern
    7. Understanding Predefined JavaScript Objects
      1. The Navigator Object
      2. The History Object
    8. Chapter 8 Self Test
  16. 9 The Document Object
    1. Defining the Document Object
    2. Using the Document Object Model
    3. Using the Properties of the Document Object
      1. Collections
      2. The cookie Property
      3. The dir Property
      4. The lastModified Property
      5. The referrer Property
      6. The title Property
      7. The URL Property
      8. The URLUnencoded Property
    4. Using the Methods of the Document Object
      1. The get Methods for Elements
      2. The open() and close() Methods
      3. The write() and writeln() Methods
    5. Using DOM Nodes
      1. DOM Node Properties
      2. DOM Node Methods
    6. Try This 9-1: Add a DOM Node to the Document
    7. Creating Dynamic Scripts
      1. Styles in JavaScript
      2. Simple Event Handling
      3. Coding a Dynamic Script
    8. Try This 9-2: Try Out Property Changes
    9. Chapter 9 Self Test
  17. 10 Event Handlers
    1. What Is an Event Handler?
    2. Why Event Handlers Are Useful
    3. Understanding Event Handler Locations and Uses
      1. Using an Event Handler in an HTML Element
      2. Using an Event Handler in the Script Code
    4. Learning the Events
      1. The Click Event
      2. Focus and Blur Events
      3. The Load and Unload Events
      4. The Reset and Submit Events
      5. The Mouse Events
      6. The Keyboard Events
    5. Try This 10-1: Focus and Blur
    6. Other Ways to Register Events
      1. The addEventListener() Method
      2. The attachEvent() Method
    7. The Event Object
      1. DOM and Internet Explorer: DOM Level 0 Registration
      2. Using event with Modern Event Registration
      3. Properties and Methods
      4. Event Information
    8. Try This 10-2: Using addEventListener()
    9. Creating Scripts Using Event Handlers
      1. Show Hidden Content
      2. Change Content
      3. Custom Events
    10. Chapter 10 Self Test
  18. 11 Introduction to Node.js
    1. Introducing Node.js
    2. Installing Node.js
      1. Check for a Current Installation
      2. Install Node.js
      3. Write a “Hello World” Script
    3. Using Node Modules
      1. Using Native Node Modules
      2. Asynchronous Execution
      3. Non-Native Modules
    4. Try This 11-1: Use a Custom Module
    5. Installing a Database
      1. Database Options
      2. Install PostgreSQL
      3. Create a Database Using pgAdmin
    6. Try This 11-2: Test Some SQL Queries
    7. Creating a Web Server
    8. Chapter 11 Self Test
  19. 12 Math, Number, and Date Objects
    1. Using the Math Object
      1. What Is the Math Object?
      2. How the Math Object Is Useful
      3. Properties
      4. Methods
    2. Try This 12-1: Display a Random Link on a Page
    3. Understanding the Number Object
      1. Properties
      2. Methods
    4. Using the Date Object
      1. Properties and Methods
      2. Methods That Get Values
      3. Methods That Set Values
      4. Other Methods
      5. How About Some Date Scripts?
    5. Try This 12-2: Create a JavaScript Clock
    6. Continuing Project
      1. Getting to the Needed Data
      2. Running Some Calculations on the Results
    7. Chapter 12 Self Test
  20. 13 Handling Strings
    1. Introduction to the String Object
      1. The String Object
      2. The String Literal
      3. What’s the Difference?
    2. Using the Properties and Methods of the String Object
      1. The length Property
    3. Methods of the String Object
    4. Try This 13-1: Use indexOf() to Test an Address
    5. Using Cookies
      1. Setting a Cookie
      2. Reading a Cookie
    6. Try This 13-2: Remember a Name
    7. Using Regular Expressions
      1. Creating Regular Expressions
      2. Testing Strings Against Regular Expressions
      3. Adding Flags
      4. Creating Powerful Patterns
      5. Grouping Expressions
      6. The replace(), match(), matchAll(), and search() Methods
      7. More Information
    8. Continuing Project
    9. Chapter 13 Self Test
  21. 14 Browser-Based JavaScript
    1. Window: The Global Object
    2. Using the Properties of the Window Object
      1. The closed Property
      2. The frames Property
      3. The innerWidth and innerHeight Properties
      4. The length Property
      5. The location Property
      6. The name Property
      7. The opener Property
      8. The parent, self, and top Properties
      9. The status and defaultStatus Properties
    3. Try This 14-1: Use the location and innerWidth Properties
    4. Using the Methods of the Window Object
      1. The alert(), prompt(), and confirm() Methods
      2. The print() Method
      3. The setInterval() and clearInterval() Methods
      4. The setTimeout() and clearTimeout() Methods
    5. Try This 14-2: Use the setTimeout() and confirm() Methods
    6. The Main Window and New Windows
      1. The Tale of Pop-up Windows
      2. Opening New Windows
      3. Closing New Windows
      4. Moving, Resizing, and Scrolling New Windows
      5. The resizeBy() and resizeTo() Methods
      6. The scrollBy() and ScrollTo() Methods
    7. Working with Images
      1. Rollovers
    8. JavaScript and Frames
      1. Purpose of Frames
      2. Accessing Frames
      3. Breaking Out of Frames
      4. Using iFrames
    9. Chapter 14 Self Test
  22. 15 JavaScript Forms and Data
    1. Accessing Forms
      1. Using the forms Array
      2. Using an ID
    2. Using the Properties and Methods of the Form Object
      1. Properties
      2. Methods
    3. Ensuring the Accessibility of Forms
      1. Using Proper Element and Label Order
      2. Using <label></label> Tags
      3. Using <fieldset></fieldset> Tags
      4. Not Assuming Client-Side Scripting
    4. Validation
      1. Simple Validation
      2. Techniques
      3. Check Boxes and Radio Buttons
    5. Try This 15-1: Request a Number
    6. HTML5 and Forms
      1. New Elements
      2. New Input Types
      3. New Attributes
      4. HTML5 Form Validation
    7. Try This 15-2: Validate a Phone Number with HTML5 or JavaScript
    8. AJAX and JSON
      1. AJAX
      2. JSON
    9. Chapter 15 Self Test
  23. 16 Further Browser-Based JavaScript
    1. Using jQuery
      1. Obtaining jQuery
      2. Getting Started: document.ready()
      3. Using Selectors
      4. Altering Classes
      5. Methods for Effects
      6. Further Reading
    2. Try This 16-1: Use jQuery to Create Effects
    3. Debugging Scripts
      1. Types of Errors
      2. Using the Console
      3. Using a Lint Tool
      4. Browser Developer Tools
    4. JavaScript and Accessibility
      1. Separate Content from Presentation
      2. Enhancing Content
    5. Try This 16-2: Make This Code Accessible
    6. JavaScript Security
      1. Page Protection
    7. JavaScript and APIs from HTML
      1. The <canvas> Element
      2. Drag and Drop
    8. Try This 16-3: Drag and Drop
    9. Node.js App Completion
      1. Update the Node.js Code
      2. Update the Front-end Code
    10. Need Help?
    11. Chapter 16 Self Test
  24. A Answers to Self Tests
    1. Chapter 1: Introduction to JavaScript
    2. Chapter 2: Placing JavaScript in an HTML File
    3. Chapter 3: Using Variables
    4. Chapter 4: Using Functions
    5. Chapter 5: JavaScript Operators
    6. Chapter 6: Conditional Statements and Loops
    7. Chapter 7: JavaScript Arrays
    8. Chapter 8: Objects
    9. Chapter 9: The Document Object
    10. Chapter 10: Event Handlers
    11. Chapter 11: Introduction to Node.js
    12. Chapter 12: Math, Number, and Date Objects
    13. Chapter 13: Handling Strings
    14. Chapter 14: Browser-Based JavaScript
    15. Chapter 15: JavaScript Forms and Data
    16. Chapter 16: Further Browser-Based JavaScript
  25. Index

Product information

  • Title: JavaScript: A Beginner's Guide, Fifth Edition, 5th Edition
  • Author(s): John Pollock
  • Release date: November 2019
  • Publisher(s): McGraw-Hill
  • ISBN: 9781260457698