Home Page Icon
Home Page
Table of Contents for
Code Snippets
Close
Code Snippets
by Kirupa Chinnathambi
JavaScript Absolute Beginner's Guide, 2nd Edition
Cover Page
About This eBook
Title Page
Copyright Page
Contents at a Glance
Register Your Book
Table of Contents
Dedication
Acknowledgments
About the Author
Figure Credits
Introduction
Parlez-vous JavaScript?
Contacting Me/Getting Help
1. Hello, World!
What Is JavaScript?
Hello, World!
Looking at the Code: Statements and Functions
Part I: The Basic Stuff
2. Values and Variables
Using Variables
More Variable Stuff
3. Functions
What Is a Function?
A Simple Function
Creating a Function that Takes Arguments
Creating a Function that Returns Data
4. Conditional Statements: if, Else, and Switch
The If / Else Statement
Switch Statements
Deciding Which to Use
5. Looping with for, While, and Do...While!
The for Loop
Some for Loop Examples
The Other Loops
6. Commenting Your Code...FTW!
What Are Comments?
Commenting Best Practices
7. Timers
Delaying with setTimeout
8. Variable Scope
Global Scope
Local Scope
Miscellaneous Scoping Shenanigans
9. Closures
Functions within Functions
When the Inner Functions Aren’t Self-Contained
10. Where Should Your Code Live?
Approach #1: All the Code Lives in Your HTML Document
Approach #2: The Code Lives in a Separate File
So...Which Approach to Use?
Part II: It’s an Object-Oriented World
11. Console Logging Basics
Meet the Console
Displaying the Console
If You Want to Follow Along
Console Logging 101
12. Of Pizza, Types, Primitives, and Objects
Let’s First Talk About Pizza
From Pizza to JavaScript!
What Are Objects?
The Predefined Objects Roaming Around in JavaScript
13. Arrays
Creating an Array
Accessing Array Values
Adding Items to Your Array
Removing Items from the Array
Finding Items in the Array
Merging Arrays
Mapping, Filtering, and Reducing Arrays
The Old School Way
Modifying Each Array Item with Map
Getting One Value from an Array of Items
A Short Foray into Functional Programming
14. Strings
The Basics
String Properties and Methods
15. When Primitives Behave Like Objects
Strings Aren’t the Only Problem
Let’s Pick on Strings Anyway
Why This Matters
16. Numbers
Using a Number
Operators
Incrementing and Decrementing
Hexadecimal and Octal Values
Special Values—Infinity and NaN
The Math Object
Random Numbers
17. Getters and Setters
A Tale of Two Properties
Meet Getters and Setters
18. A Deeper Look at Objects
Meet the Object
Creating Custom Objects
The this Keyword
19. Extending Built-In Objects
Say Hello to prototype...again—Sort of!
Extending Built-in Objects is Controversial
20. Using Classes
The Class Syntax and Object Creation
Extending Objects
21. Booleans and the Stricter === and !== Operators
The Boolean Object
The Boolean Function
Strict Equality and Inequality Operators
22. Null and Undefined
Null
Undefined
Part III: Working with the DOM
23. All About JSON (aka JavaScript Object Notation)
What Is JSON?
Looking Inside a JSON Object
Reading JSON Data
Writing JSON Data?
24. JS, the Browser, and the DOM
What HTML, CSS, and JavaScript Do
HTML Defines the Structure
Prettify My World, CSS!
It’s JavaScript Time!
Meet the Document Object Model
25. Finding Elements in the DOM
Meet the querySelector Family
It Really Is the CSS Selector Syntax
26. Modifying DOM Elements
DOM Elements Are Objects—Sort of!
Let’s Actually Modify DOM Elements
27. Styling our Content
Why Would We Set Styles Using JavaScript?
A Tale of Two Styling Approaches
Checking Whether a Class Value Exists
28. Traversing the DOM
Finding Your Way Around
Putting It All Together
29. Creating and Removing DOM Elements
Creating Elements
Removing Elements
Cloning Elements
30. In-Browser Developer Tools
Meet the Developer Tools
Part IV: Dealing with Events
31. Events
What Are Events?
Events and JavaScript
A Simple Example
The Event Arguments and the Event Type
32. Event Bubbling and Capturing
Event Goes Down. Event Goes Up.
Meet the Phases
Who Cares?
Event, Interrupted
33. Mouse Events
Meet the Mouse Events
The MouseEvent Properties
Dealing with the Mouse Wheel
34. Keyboard Events
Meet the Keyboard Events
Using These Events
The Keyboard Event Properties
Some Examples
35. Page Load Events and Other Stuff
The Things That Happen During Page Load
The DOMContentLoaded and load Events
Scripts and Their Location in the DOM
Script Elements—Async and Defer
36. Handling Events for Multiple Elements
How to Do All of This
37. Conclusion
Glossary
Index
Code Snippets
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Code Snippets
Next
Next Chapter
Code Snippets
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset