You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/miscellaneous/debugging.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@ chapter: 19
3
3
pageNumber: 122
4
4
description: In programming, errors can occur while writing code. It could be due to syntactical or logical errors. The process of finding errors can be time-consuming and tricky and is called code debugging.
5
5
---
6
+
6
7
# Debugging
7
8
8
9
In programming, errors can occur while writing code. It could be due to syntactical or logical errors. **Code debugging** is the process of identifying, isolating, and fixing errors, which can be time-consuming and tricky.
@@ -11,18 +12,19 @@ Fortunately, most modern browsers come with built-in debuggers. These debuggers
11
12
12
13
## The console.log() Technique
13
14
14
-
One of the simplest and most widely used debugging methods is using the `console.log()` function. It helps you track the flow of your code and inspect the values of variables at specific points in execution.
15
+
One of the simplest and most widely used debugging methods is using the `console.log()` function. It helps you track the flow of your code and inspect the values of variables at specific points in execution.
15
16
16
17
```javascript
17
18
functioncalculateTotal(price, taxRate) {
18
19
consttax= price * taxRate;
19
-
console.log('Tax calculated:', tax);// Output for inspection
20
+
console.log("Tax calculated:", tax); // Output for inspection
20
21
consttotal= price + tax;
21
22
return total;
22
23
}
23
24
24
25
calculateTotal(100, 0.2);
25
26
```
27
+
26
28
Use `console.log()` to:
27
29
28
30
- Check if a function is being called.
@@ -42,6 +44,7 @@ A breakpoint is a spot in your code where execution will pause, allowing you to
42
44
Modern browsers offer developer tools with debugging capabilities.
43
45
44
46
### How to Set Breakpoints
47
+
45
48
1. Open the Sources panel in DevTools.
46
49
2. Navigate to your script file.
47
50
3. Click on the line number where you want execution to pause.
@@ -52,9 +55,10 @@ Once paused, you can:
52
55
-**Step into** – dive into a function call.
53
56
-**Step out** – exit the current function.
54
57
-**Resume** – continue execution until the next breakpoint.
55
-
Breakpoints are non-intrusive and can be added/removed without changing your code.
58
+
Breakpoints are non-intrusive and can be added/removed without changing your code.
56
59
57
60
## Browser Developer Tools
61
+
58
62
Modern browsers come equipped with powerful developer tools that aid in debugging JavaScript, inspecting HTML and CSS, and monitoring network requests. Here's a brief overview of some essential tools:
59
63
60
64
**Chrome DevTools:** Google Chrome's developer tools offer a wide range of features for debugging web applications.
@@ -71,6 +75,7 @@ Browsers provide a set of developer tools that allow you to inspect HTML, CSS, a
71
75
We can access them by right-clicking on a web page and selecting "Inspect" or by pressing `F12` or `Ctrl+Shift+I`/ `Cmd + Option + I` (Mac).
72
76
73
77
### Key Panels in Developer Tools
78
+
74
79
-**Console:** Displays logs, errors, and allows executing JS in real time.
75
80
-**Elements / Inspector:** Lets you browse and edit the HTML and CSS.
76
81
-**Sources:** Where you debug JavaScript using breakpoints.
@@ -83,7 +88,7 @@ We can insert the debugger statement in the code to create breakpoints programma
83
88
84
89
In the DevTools, you can **watch** variables or expressions. This is helpful when debugging complex logic or tracking a variable over time.
85
90
86
-
- Use the **Watch** panel to track expressions like user.name or cart.length.
91
+
- Use the **Watch** panel to track expressions like `user.name` or `cart.length`.
87
92
- View **Local**, **Closure**, and **Global** scopes to inspect available variables.
88
93
89
94
### Stack Trace and Call Stack
@@ -92,7 +97,7 @@ When paused at a breakpoint (or after an error), you can inspect the Call Stack
92
97
93
98
- It shows the series of function calls that led to the current point.
94
99
- Clicking on a frame lets you inspect variables in that context.
95
-
Understanding the call stack is vital for fixing unexpected behaviors caused by incorrect function flows.
100
+
Understanding the call stack is vital for fixing unexpected behaviors caused by incorrect function flows.
96
101
97
102
## Common Debugging Strategies
98
103
@@ -102,4 +107,3 @@ Understanding the call stack is vital for fixing unexpected behaviors caused by
102
107
-**Search for error messages**: JavaScript errors often contain helpful information.
103
108
-**Check browser compatibility**: Not all browsers behave identically.
104
109
-**Use linters**: Tools like ESLint can catch many common bugs before you run your code.
Copy file name to clipboardExpand all lines: es/miscellaneous/debugging.md
+9-3Lines changed: 9 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@ chapter: 19
3
3
pageNumber: 152
4
4
description: En programación, pueden ocurrir errores al escribir código. Podría deberse a errores sintácticos o lógicos. El proceso de encontrar errores puede llevar mucho tiempo y ser complicado y se denomina depuración de código.
5
5
---
6
+
6
7
# Depuración
7
8
8
9
En programación, es común que ocurran errores mientras se escribe el código. Estos pueden ser errores sintácticos o lógicos. La depuración de código es el proceso de identificar, aislar y corregir estos errores, lo cual puede ser un proceso complicado y que consume tiempo.
@@ -16,7 +17,7 @@ Una de las formas más simples y populares de depurar código es utilizando la f
console.log('Impuesto calculado:', impuesto);// Salida para inspección
20
+
console.log("Impuesto calculado:", impuesto); // Salida para inspección
20
21
consttotal= precio + impuesto;
21
22
return total;
22
23
}
@@ -44,6 +45,7 @@ Un punto de interrupción es una línea en tu código donde la ejecución se det
44
45
Los navegadores modernos ofrecen herramientas para desarrolladores con capacidades de depuración.
45
46
46
47
### Cómo establecer puntos de interrupción
48
+
47
49
1. Abre el panel Sources en las DevTools.
48
50
2. Navega hasta tu archivo de script.
49
51
3. Haz clic en el número de línea donde quieres que la ejecución se detenga.
@@ -70,10 +72,12 @@ Los navegadores modernos vienen equipados con potentes herramientas de desarroll
70
72
**Safari Web Inspector:** Web Inspector de Safari es un sólido conjunto de herramientas para depurar y crear perfiles de aplicaciones web.
71
73
72
74
### Acceso a las herramientas del navegador
75
+
73
76
Los navegadores ofrecen herramientas para inspeccionar HTML, CSS y JavaScript. Podemos acceder a ellas:
74
77
Haciendo clic derecho sobre la página y seleccionando "Inspeccionar" o presionando `F12` o `Ctrl + Shift + I` / `Cmd + Option + I` (Mac)
75
78
76
79
### Paneles clave en las herramientas del navegador
80
+
77
81
-**Console (Consola)**: Muestra registros, errores y permite ejecutar JavaScript en tiempo real.
78
82
-**Elements / Inspector**: Permite examinar y modificar el HTML y CSS del documento.
79
83
-**Sources**: Lugar donde se depura JavaScript usando puntos de interrupción.
@@ -83,17 +87,19 @@ Haciendo clic derecho sobre la página y seleccionando "Inspeccionar" o presiona
83
87
Podemos insertar la instrucción debugger directamente en el código para crear un punto de interrupción de forma programada. Cuando el código encuentra debugger, se pausará la ejecución y se abrirán las herramientas de desarrollo del navegador (si están abiertas).
84
88
85
89
### Expresiones de vigilancia y alcance (Watch & Scope)
90
+
86
91
En las DevTools puedes vigilar variables o expresiones. Esto es útil cuando depuras lógica compleja o haces seguimiento de una variable a lo largo del tiempo.
87
92
88
-
- Usa el panel Watch para seguir expresiones como usuario.nombre o carrito.length.
93
+
- Usa el panel Watch para seguir expresiones como `usuario.nombre` o `carrito.length`.
89
94
- Examina los alcances Local, Closure y Global para inspeccionar las variables disponibles en cada contexto.
90
95
91
96
### Rastreo de pila y Call Stack
97
+
92
98
Cuando el código se detiene en un punto de interrupción (o tras un error), puedes inspeccionar el panel de Call Stack:
93
99
94
100
- Muestra la secuencia de funciones llamadas que llevaron hasta el punto actual.
95
101
- Al hacer clic en un marco (frame), puedes examinar variables en ese contexto.
96
-
Entender la pila de llamadas es esencial para corregir comportamientos inesperados producidos por un flujo de ejecución incorrecto.
102
+
Entender la pila de llamadas es esencial para corregir comportamientos inesperados producidos por un flujo de ejecución incorrecto.
0 commit comments