Skip to content

Instantly share code, notes, and snippets.

@DevGW
Created December 29, 2022 13:45
Show Gist options
  • Save DevGW/d57a835d14679d81c9139276d88c99d7 to your computer and use it in GitHub Desktop.
Save DevGW/d57a835d14679d81c9139276d88c99d7 to your computer and use it in GitHub Desktop.
Javascript :: debugging
/* To use debugger:
1. add the debugger keyword in your function is VSCode
2. invoke the function yourself */
function onlyOdds(num) {
debugger; // debugger keyword here
let sum = 0;
for (let i = num; i >= 1; i--) {
if (i % 2 === 1) {
sum += i;
}
}
return sum;
}
onlyOdds(3); // invoking the function ourselves here
/* Then, click the debugging option in VSCode
followed by the green debug arrow at the top-left of the screen.
Now, press down arrow dot to see your code run line by line (press red square to stop) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment