SitePoint
Blog
Forum
Library
Login
Join Premium
Toggle sidebar
Learn to Code with JavaScript
Toggle community discussions
Close
Content
Bookmarks
Preface
Learn to Code with JavaScript
Notice of Rights
Notice of Liability
Trademark Notice
About Darren Jones
About SitePoint
Preface
Who Should Read This Book?
Conventions Used
Supplementary Materials
1
Press Start
Programming
A Brief History of Programming
JavaScript
Hello, World! Your First JavaScript Program
JavaScript in the Browser
I Can Code a Rainbow: Your Second JavaScript Program
A Programmer’s Mindset
Challenges
Summary
Programming Basics
Comments
Programming Grammar
Variables
Pop-up Interaction
Challenges
Summary
Letters And Words
Chars and Strings
Template Literals
Challenges
Summary
Numbers
Integers and Floats
Numeric Literals
Exponential Notation
When Is a Number Not a Number?
Arithmetic Operations
Varying Variables
Increments
How Old?
Calculations with Numbers and Strings
Converting Between Strings and Numbers
Random Numbers
More Methods
Challenges
Summary
Collections
Arrays
Arrays in JavaScript
Multi-dimensional Arrays
Challenges
Summary
Logic
Booleans
Logical Operators
Comparison
Flow Control
What’s Your Favorite Animal?
Rock Paper Scissors
Challenges
Summary
Going Loopy
What’s a Loop?
Infinite Loops
While Loops
Do–while Loops
For Loops
Nested Loops
Challenges
Summary
Functions
Functions in JavaScript
Return Values
Parameters and Arguments
Callbacks
Choosing the Right Type of Function
Challenges
Summary
Objects
Properties and Methods
Creating Objects in JavaScript
Properties and Methods
Roll the Dice
Challenges
Summary
The Document Object Model
The Document Object Model
Getting an Element
Updating the HTML
Getting Multiple Elements
Navigating the DOM Tree
Creating Dynamic Markup
Getting and Setting Attributes
Doing It with Style
A Simple To-do List
Challenges
Summary
The Main Event
Event-based Programming
Click Events
Forms
Keyboard Events
Mouse Events
Simple To-do List
Challenges
Summary
Going Loopy Over Arrays
Spreading Strings
Array Iteration Methods
Find
Every
Iterating over Objects
To-do List Project
Challenges
Summary
Let's Get Functional
Named Parameters
The Rest Parameter
Recursive Functions
Scope
Hoisting
Functions That Return Functions
Closures
Functional Programming
Pure Array Updates
Challenges
Summary
Getting Classy
Copying Objects in JavaScript
Object-oriented Programming
Classes
Classy Components
The Pet Unicorn Game
Challenges
Summary
It's About Time
The UNIX Epoch
Times and Dates
Timing Functions
Asynchronous Programming
Intervals
Animation
Cookie Grabber Game
Challenges
Summary
End Of Line
Coding Best Practice
Going Further with JavaScript
Learn Another Language
Always Learning
Carry On Coding
Internet of Things
Challenges
Summary
Open text modal
Community Questions
Close