Skip to Content
JavaScript Essentials For Dummies
book

JavaScript Essentials For Dummies

by Paul McFedries
April 2024
Beginner content levelBeginner
192 pages
3h 21m
English
For Dummies
Content preview from JavaScript Essentials For Dummies

Chapter 11

Ten JavaScript Debugging Strategies

IN THIS CHAPTER

Bullet Debugging with the Console, breakpoints, and other dev power tools

Bullet Writing code to make it easier to debug

Bullet Craftily debugging with comments

Given any nontrivial JavaScript code, it’s a rare (probably nonexistent!) script that runs perfectly the first (or even the tenth!) time. Script bugs happen to even the most experienced developers, so having errors in your code does not mean you’re a failure as a coder! All it means is that you’re a coder.

But when bugs get into your code, you’ll want to exterminate them as quickly as you can. This chapter provides you with ten debugging strategies that can help.

Get Thee to Your Dev Tools

All web page debugging begins with a visit to your web browser development tools. In every browser, the quickest way to open the dev tools is to right-click a page element and then click Inspect. You can also press Ctrl+Shift+I (Windows) or Option⌘  +I (macOS).

The Console Is Your Best Debugging Friend

In your code, you can see the current value of a variable or object property by outputting that value to the dev tools Console tab:

console.log(output);

Replace output with the expression you ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript All-in-One For Dummies

JavaScript All-in-One For Dummies

Chris Minnick

Publisher Resources

ISBN: 9781394263219Purchase Link