12/04/2026 18:17pm

JS2GO EP.17 Debugging Code in Go and JavaScript
#Go
#JavaScript
#VS Code Debugger
#Debugging
#Code Debugging
Debugging is an essential process in software development that helps identify and fix issues in the code effectively. Go and JavaScript each have their own debugging tools and techniques. In this article, we’ll explore how debugging works in both languages, along with examples and tools that can assist in inspecting and fixing errors in the code.
Debugging in Go
Using Print Statements
In Go, debugging typically begins with using print statements to show the values of variables at different points in the code.
Example of debugging with print statements:
package main
import "fmt"
func add(a, b int) int {
fmt.Println("Adding:", a, b) // Print the values of a and b before calculation
return a + b
}
func main() {
result := add(3, 4)
fmt.Println("Result:", result)
}
Advantages:
✨ Simple and convenient to check variable values during execution.
Disadvantages:
⚠️ Makes the code cluttered and needs to be removed after debugging.
Using Delve (Debugging Tool)
Delve is a tool specifically used for debugging Go code. It allows you to pause the program at specific points and inspect variable values.
Installing Delve:
go get -u github.com/go-delve/delve/cmd/dlv
Example of debugging with Delve:
dlv debug main.go
Advantages:
✨ Allows you to pause the program and inspect operations at specific points.
Disadvantages:
⚠️ Requires additional tool installation and learning how to use it.
Debugging in JavaScript
Using Console.log
In JavaScript, the simplest debugging method is using console.log() to print the values of variables or messages at various stages of the program.
Example of debugging with console.log:
function add(a, b) {
console.log("Adding:", a, b); // Print the values of a and b
return a + b;
}
let result = add(3, 4);
console.log("Result:", result);
Advantages:
✨ Easy to use without installing additional tools.
✨ Can be used anywhere in the code.
Disadvantages:
⚠️ In large projects, it can clutter the code and make it harder to read.
Using Debugger in Browser DevTools
Browser Developer Tools (e.g., Chrome) include a Debugger that helps you pause the program and inspect values interactively.
How to use the Debugger in Chrome:
- Open Developer Tools (F12 or Ctrl + Shift + I).
- Go to the "Sources" tab.
- Click on the line where you want to pause the program (Set Breakpoint).
- Run the code in the program.
Advantages:
✨ Interactive debugging with the ability to inspect variable values while the program is running.
✨ Supports step-over, step-into, and watch expressions.
Disadvantages:
⚠️ Must be used through a browser, and in some cases, you can’t debug code not related to browser-based operations.
Using Visual Studio Code (VS Code) Debugger
VS Code is an IDE that efficiently supports debugging JavaScript code.
Example of setting up the Debugger in VS Code:
- Open the
launch.jsonfile in the.vscodefolder and add a new configuration. - Select "JavaScript (Node.js)" for Node.js projects.
- Use breakpoints to pause the program at specific points.
Advantages:
✨ Convenient for debugging Node.js or JavaScript running in a browser.
✨ Easy to use in VS Code.
Disadvantages:
⚠️ Requires installation and proper setup of VS Code.
Comparing Debugging in Go and JavaScript
| Feature | Go | JavaScript |
|---|---|---|
| Main Debugging Tools | Delve, Print Statements | Console.log, Browser DevTools, VS Code Debugger |
| Ease of Use | Requires special tools like Delve | Easy to use via console.log or DevTools |
| Flexibility | Interactive debugging via Delve | Can stop and inspect directly in DevTools |
| Best for | Large systems, strict typing | Web apps, flexible OOP |
| Limitations | Need to learn extra tools | No advanced features in some cases (e.g., multiple breakpoints) |
Summary and Recommendations
Go uses the Delve tool, which provides an efficient way to debug code and inspect errors thoroughly, especially in large and complex systems.
JavaScript uses console.log for simple code debugging or DevTools in browsers for interactive debugging.
If you are developing a large project in Go, it is recommended to use Delve for debugging. Meanwhile, JavaScript uses DevTools for debugging in web applications or browser-based projects.
Next Episode:
In EP.18 of the JS2GO series, we will dive into code formatting and linting in Go and JavaScript to help ensure your code is clean and of high quality.
If you want to learn about debugging code in Go and JavaScript and improve your programming skills, Superdev Academy is here to help! Sign up with us today!
Read more
🔵 Facebook: Superdev Academy
🔴 YouTube: Superdev Academy
📸 Instagram: Superdev Academy
🎬 TikTok: https://www.tiktok.com/@superdevacademy?lang=th-TH
🌐 Website: https://www.superdevacademy.com/en