The Most Important Skill You Never Learned

Web Dev Simplified
4 Jun 202434:55

Summary

TLDRThis video script offers an in-depth guide on debugging for web developers, covering essential techniques from basic to advanced levels. The tutorial begins with understanding error messages and using console logs for simple bugs, then progresses to utilizing the Chrome DevTools for a more sophisticated debugging approach. It explores setting breakpoints, stepping through code, and leveraging the watch tab for monitoring variable values. Additionally, the script delves into using Visual Studio Code for debugging, examining network requests, and analyzing performance with the Lighthouse tab. The aim is to minimize bug-finding time and maximize coding efficiency, ultimately helping developers to master JavaScript and build robust projects.

Takeaways

  • πŸ˜• Debugging is a crucial skill often overlooked by developers, which can significantly reduce coding efficiency.
  • πŸ” Learning advanced debugging techniques is essential for developers of all skill levels to minimize time spent finding bugs.
  • πŸ“š The video offers a comprehensive guide on debugging, ranging from basic to advanced concepts.
  • πŸ’‘ Understanding error messages and their locations is the first step in resolving coding issues.
  • πŸ‘€ The 'Topline message' in an error provides insight into the nature of the error, while the script and line number indicate where it occurred.
  • πŸ”§ Simple bugs can often be fixed by correcting variable names or function calls, as demonstrated in the video.
  • πŸ”¦ Console log statements are a basic but effective method for tracking variable values and code execution flow.
  • πŸ› οΈ The 'debugger' keyword in JavaScript serves as a built-in tool to pause code execution for inspection.
  • πŸ”„ Step functions like 'step over', 'step in', and 'step out' are vital for navigating through code execution during debugging.
  • πŸ”— Breakpoints can be set in the code to pause execution at specific points, aiding in the investigation of complex issues.
  • 🌐 The video also covers the use of Chrome's Developer Tools for advanced debugging, including the Network, Performance, and Application tabs.

Q & A

  • Why is learning to debug properly considered an important skill for developers?

    -Learning to debug properly is considered an important skill for developers because it allows them to minimize the time spent finding and fixing bugs, thus enabling them to spend more time writing code, which is often considered more enjoyable.

  • What is the first step a beginner should take when debugging code?

    -The first step a beginner should take when debugging code is to understand how to use the tools provided for debugging, such as utilizing console log statements to figure out what is happening inside the code and examining the error messages for clues about the problem.

  • What information does the 'uncaught reference error' provide about the code?

    -The 'uncaught reference error' indicates that a variable or function is being referenced in the code but has not been defined. It also provides additional information such as the specific line number in the script file where the error occurred.

  • How can console log statements assist in debugging?

    -Console log statements can assist in debugging by providing insights into the values of variables at different points in the code. They help developers track the execution flow and determine if variables contain the expected values, thus identifying where things might be going wrong.

  • What is the purpose of the 'debugger' keyword in JavaScript?

    -The 'debugger' keyword in JavaScript is used to pause the execution of the code at that point. It allows developers to inspect the call stack, scope, and variables at that particular moment, making it easier to understand the code's behavior and identify bugs.

  • What are the different functions of the buttons available in the debugger tool?

    -The buttons in the debugger tool allow developers to control the execution of the code. They can 'Resume' to continue execution, 'Step Over' to move to the next line, 'Step In' to go into a function call, 'Step Out' to exit the current function, and 'Step' to move through the code in execution order, which is particularly useful for asynchronous code.

  • How can breakpoints be used to debug code in the Chrome Developer Tools?

    -Breakpoints can be set at specific lines in the code to pause execution at those points. This allows developers to inspect the state of the application, including variable values and the call stack, to understand the flow and identify issues. Breakpoints can be set manually by clicking on the line number or by using the 'debugger' keyword.

  • What is the significance of the 'call stack' in debugging?

    -The 'call stack' in debugging shows the sequence of function calls up to the current point in the execution of the program. It helps developers understand the order in which functions are being called and the scope of variables at each level, which can be crucial for tracking down bugs related to function calls.

  • How can event listener breakpoints be used to debug event handling code?

    -Event listener breakpoints allow developers to pause execution whenever a specific event occurs. This is useful for debugging event handling code where it may be unclear which part of the code is being triggered by an event. By setting an event listener breakpoint, the debugger will pause at the exact line where the event is being handled.

  • What is the advantage of using the 'watch' tab in the debugger?

    -The 'watch' tab in the debugger allows developers to monitor the value of a specific variable or expression throughout the code execution. This can be particularly useful for tracking changes to a variable within a large function or for evaluating more complex expressions that involve multiple variables.

  • How can Visual Studio Code be used for debugging instead of the Chrome Developer Tools?

    -Visual Studio Code can be used for debugging by setting up a debugging configuration that launches the application in a browser and attaches the debugger. This allows developers to take advantage of the full code editor environment, set breakpoints, inspect variables, and step through the code, all within Visual Studio Code.

  • What is the purpose of the 'Network' tab in the Chrome Developer Tools?

    -The 'Network' tab in the Chrome Developer Tools allows developers to monitor and analyze the network activity of the page. It shows all the resources fetched, their types, sizes, timing, and other details. This is useful for debugging issues related to resource loading, such as slow-loading resources or failed requests.

  • What kind of performance issues can be identified using the 'Performance' tab in Chrome Developer Tools?

    -The 'Performance' tab in Chrome Developer Tools can be used to record and analyze the runtime performance of a page. It can help identify long-running scripts, layout thrashing, jank, and other performance bottlenecks by providing a detailed breakdown of the time taken for various processes and events during page load and interaction.

  • How can the 'Application' tab be used to debug issues related to storage and data?

    -The 'Application' tab in Chrome Developer Tools provides access to various storage and data interfaces used by the page, such as Local Storage, Session Storage, Cookies, and IndexedDB. Developers can use this tab to view, modify, and debug the data stored in these interfaces, which can be helpful for troubleshooting issues related to data persistence and state management.

  • What insights can the 'Lighthouse' tab provide for improving website performance and quality?

    -The 'Lighthouse' tab in Chrome Developer Tools runs a series of audits to provide insights and suggestions for improving the performance, accessibility, SEO, and best practices of a website. It generates a report with a score for each category and highlights specific issues and opportunities for optimization.

Outlines

00:00

πŸ› The Essentials of Debugging in Coding

The paragraph introduces the importance of debugging in software development, emphasizing it as a critical skill often overlooked by developers. It highlights the goal of the video to provide a comprehensive guide on debugging, ranging from basic to advanced techniques. The speaker, Kyle, aims to teach viewers how to efficiently find and fix bugs, thus spending more time on the enjoyable aspect of coding. The paragraph also mentions the structure of the video, including timestamps for different skill levels and a basic example of a debugging scenario involving a simple function with an error.

05:02

πŸ” Understanding and Utilizing Debugging Tools

This section delves into the basics of debugging by demonstrating how to use built-in tools to identify and solve code problems. It explains the process of reading error messages, pinpointing the location of errors within the code, and understanding the significance of the error details provided. The paragraph walks through a practical example where a typo in a function call is corrected using these debugging techniques. It also touches on the challenge of debugging when no error message is displayed, illustrating how to use 'console.log' statements to track and understand the flow and values within the code.

10:02

πŸ› οΈ Advanced Debugging with the Debugger Keyword

The paragraph discusses the use of the 'debugger' keyword in JavaScript as a tool for advanced debugging. It explains how inserting the keyword into the code allows the program to pause its execution, providing an opportunity to inspect variable values and code execution. The speaker demonstrates the functionality of the debugger in Chrome's developer tools, showcasing features like 'step over', 'step in', and 'step out' which help navigate through the code line by line or into functions. Additionally, the difference between 'step' and 'step into' is clarified in the context of asynchronous code, and the paragraph concludes with a brief mention of other capabilities of the Chrome debugger.

15:04

πŸ“Œ Mastering Breakpoints and Call Stacks

This section focuses on the advanced use of breakpoints and call stacks in debugging. Breakpoints can be set to pause execution at a specific line of code, and the paragraph explains different methods to set them, including using the Chrome debugger interface or clicking on the line number in the code. It also covers 'XHR fetch breakpoints' and 'event listener breakpoints', which allow developers to pause execution at specific events or fetch requests. The call stack is introduced as a tool to view the order of function calls and understand the scope of variables at each level. The paragraph concludes with a discussion on the practicality of breakpoints for identifying the source of errors and navigating complex code structures.

20:06

🌐 Exploring DOM and Global Breakpoints

The paragraph discusses various types of breakpoints related to DOM manipulation and global events. It explains how to set breakpoints for node removal, attribute modification, and subtree modifications within the DOM. The concept of 'Global listeners' and 'CSP violation breakpoints' is introduced, which allow developers to monitor and pause execution on specific global events or content security policy violations. The speaker also demonstrates how to use these breakpoints in practice by adding a class to an element and appending a child to the body, showing how the debugger pauses at the exact line where the change occurs.

25:07

πŸ”§ Debugging with Watch Expressions and Visual Studio Code

This section introduces the 'Watch' tab in the debugger, which allows developers to monitor the value of a variable or a custom JavaScript expression throughout the code execution. The speaker then transitions to demonstrating how to use Visual Studio Code (VS Code) for a more integrated debugging experience. The paragraph explains how to set up a debugging configuration in VS Code to run a web application in Chrome, and it highlights the benefits of using VS Code for debugging, such as the ability to add breakpoints, watch variables, and view the call stack without leaving the editor. The paragraph also covers advanced breakpoint features in VS Code, such as conditional breakpoints and log points.

30:07

πŸ“‘ Utilizing Network, Performance, and Other Chrome Developer Tools

The final paragraph covers additional features of the Chrome Developer Tools, starting with the 'Network' tab, which provides insights into all the resources fetched during page loading. The speaker explains how to use this tab to monitor network activity, disable cache, and throttle network speed to simulate different network conditions. The 'Performance' tab is also briefly introduced as a tool for profiling and identifying performance bottlenecks. The paragraph concludes with a mention of the 'Application' tab for inspecting and modifying storage and the 'Lighthouse' tab for auditing page performance, SEO, and accessibility, emphasizing the comprehensive nature of these tools for debugging and optimizing web applications.

Mindmap

Keywords

πŸ’‘Debugging

Debugging is the process of finding and resolving bugs or defects in code. It is a fundamental skill for developers, as depicted in the video, where the presenter emphasizes its importance regardless of one's skill level. The video's theme revolves around teaching various debugging techniques, from basic to advanced, to minimize the time spent on finding bugs and maximize the time for writing code.

πŸ’‘Error Messages

Error messages are notifications provided by programming environments that indicate something has gone wrong. In the context of the video, error messages are crucial for debugging as they provide information about what went wrong and where it occurred. An example from the script is the 'uncaught reference error' which helps identify that a variable is not defined.

πŸ’‘Console Log

Console log is a tool used in debugging that outputs information to the browser's JavaScript console. It helps developers understand the flow of execution and the values of variables at different points in the code. The video script illustrates its use when the presenter adds 'console.log' statements to track the value of variables and determine the flow of execution within functions.

πŸ’‘Debugger

The 'debugger' is a keyword in JavaScript that, when encountered during code execution, pauses the execution and allows the developer to inspect the call stack, scope, and variables. The video demonstrates the use of 'debugger' to pause code at a specific point and examine the state of the application, which is essential for understanding and fixing complex issues.

πŸ’‘Breakpoints

Breakpoints are markers in the code that tell the debugger to pause execution at that point. They are used to halt the program at a specific line for inspection. The video explains how to set breakpoints in the Chrome debugger and in Visual Studio Code, and how they can be used to pause the execution of the program for further analysis.

πŸ’‘Call Stack

The call stack is a data structure that tracks function calls in chronological order. It helps developers understand the order in which functions are called and is vital for debugging nested function calls. The video script describes how the call stack can be used to navigate through the different levels of function calls and inspect the scope of variables at each level.

πŸ’‘Event Listener Breakpoints

Event listener breakpoints are a type of breakpoint that pauses code execution when a specific event occurs, such as a mouse click or key press. The video mentions how these breakpoints can be useful for debugging event-driven code, allowing developers to inspect the state of the application at the moment the event is triggered.

πŸ’‘DOM Breakpoints

DOM breakpoints allow developers to set breakpoints on specific changes to the Document Object Model (DOM), such as when an element is added, removed, or modified. The script describes how these breakpoints can be used to pause execution when changes occur to the DOM, which is helpful for debugging dynamic web applications where the UI updates in response to user interactions.

πŸ’‘Conditional Breakpoints

Conditional breakpoints are a type of breakpoint that only triggers when a specific condition is met. They are useful for complex applications where you want to pause execution under certain circumstances. The video script explains how to set a conditional breakpoint based on the value of a variable, allowing for more targeted debugging.

πŸ’‘Watch Tab

The watch tab is a feature in debuggers that allows developers to keep an eye on the values of specific variables or expressions. It helps in tracking changes to variable values throughout the code execution. The video demonstrates how to use the watch tab to monitor variable values, which can be particularly useful when dealing with complex logic or when a variable's value is hard to trace.

πŸ’‘Network Tab

The network tab in developer tools shows all the network requests made by the page, including their timing, headers, and responses. It is instrumental for debugging issues related to fetching resources. The video script discusses how the network tab can be used to monitor and analyze network requests, which is essential for understanding performance bottlenecks or issues with external resources.

πŸ’‘Performance Tab

The performance tab in developer tools allows developers to record and analyze the runtime performance of a page. It provides insights into where bottlenecks may occur during page load or execution. The video briefly touches on how this tab can be used to profile the performance of web applications and identify slow or inefficient processes.

πŸ’‘Lighthouse Tab

The Lighthouse tab is a tool within Chrome DevTools that analyzes web pages and provides feedback on performance, accessibility, SEO, and more. It's a valuable debugging tool for auditing the overall quality of web pages. The video script mentions how Lighthouse can be used to identify and fix various issues, helping developers improve the quality of their web applications.

Highlights

Debugging is a crucial skill often overlooked by developers, which can significantly reduce coding time and increase efficiency.

The video provides a comprehensive guide on debugging from basics to advanced techniques.

Understanding error messages and their locations is fundamental for effective debugging.

Simple typos or reference errors can be quickly identified and resolved by examining the error message details.

The importance of using console log statements to track variable values and code execution flow.

Advanced debugging involves using the 'debugger' keyword to pause code execution for inspection.

The video demonstrates how to use the 'step over', 'step in', and 'step out' functions for detailed code inspection.

The difference between 'step into' and 'step' functions, especially in asynchronous code scenarios.

Utilizing breakpoints to pause code execution at specific points without modifying the code with 'debugger' statements.

The 'call stack' feature helps in understanding the order of function calls and variable scopes.

Breakpoints can be set on specific events, such as 'fetch' requests or DOM modifications, for targeted debugging.

The 'watch' tab allows developers to monitor variable values and expressions in real-time.

Integrating Chrome's debugging capabilities into Visual Studio Code (VS Code) for a more integrated development experience.

VS Code supports conditional breakpoints, log points, and triggered breakpoints for advanced debugging scenarios.

The 'Network' tab in Chrome is essential for monitoring and debugging network requests and responses.

The 'Performance' tab provides insights into the runtime performance of web applications.

The 'Application' tab helps in debugging and manipulating data stored in local storage, session storage, cookies, and IndexedDB.

Lighthouse tab offers a comprehensive analysis of web page performance, SEO, and accessibility.

Transcripts

play00:00

the most frustrating part about coding

play00:02

hands down is trying to find and fix

play00:04

bugs in your code this is why learning

play00:06

how to debug properly is an incredibly

play00:08

important skill that most developers

play00:10

completely skip over and it doesn't

play00:12

matter what skill level you're currently

play00:14

at learning how to properly debug using

play00:16

Advanced Techniques is incredibly

play00:18

important so in this crash course video

play00:20

I'm going to teach you everything you

play00:21

need to know about debugging from the

play00:23

absolute Basics all the way to the most

play00:25

advanced concepts you need to understand

play00:27

in order to make sure that you can

play00:28

minimize the amount of time you spend

play00:29

finding bugs so you can spend more of

play00:31

your time writing code which we all know

play00:33

is way more

play00:36

fun welcome back to web dev simplified

play00:39

my name is Kyle and my job is to

play00:40

simplify the web for you so you can

play00:42

start building your dream project sooner

play00:43

now since I'm going to be covering

play00:45

everything from beginner to Advan

play00:46

Concepts in this video I want to put

play00:48

time stamps in the description so you

play00:49

can jump around to the exact skill level

play00:51

you're currently at now if you're an

play00:53

absolute beginner when it comes to

play00:54

debugging the first important thing to

play00:56

understand is how you can actually use

play00:58

the tools that are given to you to debug

play01:00

bug certain problems that come up in

play01:01

your code for example in this code I

play01:03

have some really simple stuff going on I

play01:04

have a function called print name takes

play01:06

in a first name and a last name and it

play01:08

just combines together the first name

play01:09

and the last name and down here if I

play01:11

just pass in for example Kyle and I pass

play01:13

in cook that should print out Kyle cook

play01:16

but when I save you can see we're

play01:17

getting an error immediately uncaught

play01:18

reference error fit name is not defined

play01:21

and it gives me some other information

play01:22

after that now we'll get that in just a

play01:24

second I want to finish understanding

play01:25

what the rest of the code does this next

play01:27

function is called print end times all

play01:29

it does is you pass in how many times

play01:30

you want to print something and the

play01:31

thing that you want to print and it

play01:33

should print that thing that many times

play01:34

so as you can see down here I'm calling

play01:35

that pass it in in five and the value

play01:37

high so it should print out high five

play01:39

separate times and then finally I just

play01:40

have a simple event listener on my

play01:42

document so every time I click on it it

play01:43

should print out clicked super

play01:45

straightforward but for now you can see

play01:47

we have this error so immediately when

play01:48

you get an error like this the most

play01:50

important thing to look at is going to

play01:51

be this Topline message right here which

play01:53

tells you what the error is in our case

play01:55

it's an uncaught reference error and

play01:57

here's a little bit more information on

play01:58

What that particular reference error is

play02:01

and then the next most important thing

play02:02

to look at is going to be this section

play02:04

right here which tells you exactly in

play02:05

your code where this happened so in our

play02:07

case it's saying this happened in our

play02:08

script.js file on line two so if we go

play02:11

into this file and we go down to line

play02:13

two you can see this is where the error

play02:15

is occurring now without any more

play02:17

information it's kind of hard for us to

play02:18

tell what's going on but if we look at

play02:19

this uncaught reference there it says

play02:21

fit name is not defined so that means

play02:23

this fit name variable is not defined

play02:25

but is trying to be used in this

play02:26

particular case all I did is I

play02:28

misspelled first name as fit name so if

play02:30

I were to actually fix this by properly

play02:32

spelling first name and I give it a save

play02:34

you can see immediately that fixes that

play02:37

particular error that we had so I bring

play02:39

this back the most important thing to

play02:40

look at anytime you get an error message

play02:42

is going to be where that error message

play02:43

occurred so this gives you the exact

play02:44

line number and also looking at exactly

play02:46

what the error message tells you is

play02:48

happening also if that isn't enough

play02:50

information it'll also give you more

play02:52

information on exactly where it's called

play02:54

if it's nested inside like seven

play02:56

different functions so if you call like

play02:57

print age then call Print name and then

play02:59

call something something else after that

play03:00

it'll tell you the exact order of all

play03:02

these events in this section down here

play03:04

in our case we're calling just one

play03:05

function so that's why you can see it

play03:07

has one line here for our function and

play03:08

then one line for our main script file

play03:10

and that's all that's happening as you

play03:11

can see this is saying on line 17 which

play03:13

as you can see is essentially where

play03:15

we're calling that function and if we

play03:16

had more nesting we would have more

play03:17

entries inside of this telling us

play03:19

exactly the order of all that nesting so

play03:21

that gives you a high level information

play03:23

of what to look for now let's go back

play03:24

and fix that error again and we'll

play03:26

notice we have another bug but this one

play03:27

doesn't actually show us an error and

play03:29

these are by far the hardest to actually

play03:31

debug because usually an error message

play03:32

is good at telling you what's wrong but

play03:34

if you don't get an error message it

play03:35

means something's wrong with your code

play03:37

most likely because of how you wrote it

play03:38

so in our case here Kyle Cook is

play03:40

printing out exactly like we expected to

play03:42

but right here we're calling print n

play03:44

times and it should print out the value

play03:45

high five separate times but instead

play03:47

it's printing out five five separate

play03:49

times so clearly there's something going

play03:50

on inside of our code now in our

play03:52

particular case it's really easy to read

play03:54

this function cuz it's only three lines

play03:56

and figure out what the problem is in

play03:57

our case you can see here that I'm

play03:59

console loing n instead of console

play04:01

logging our value if I were to swap this

play04:03

out with value and I give it a save you

play04:05

can now see it prints out high five

play04:06

times instead of n five times so this

play04:09

one was pretty easy to figure out just

play04:10

by looking at exactly what's going on

play04:12

but a lot of times your functions are

play04:14

going to be more complicated maybe you

play04:15

have a 100 lines of code you're trying

play04:17

to read through with a bunch of

play04:18

different if statements and variables

play04:19

being created concatenated changed and

play04:21

so on so it's hard to keep track of

play04:23

exactly what the particular value of all

play04:25

your different variable is throughout

play04:27

the entire essentially function that's

play04:28

running so instead what you can do is

play04:30

you can put in console log statements to

play04:32

try to figure out what's going on inside

play04:34

your code so for example let's bring

play04:36

this back to the broken code that we had

play04:38

before and what I could do is I could

play04:39

say you know what for some reason it's

play04:41

printing out five I wonder if my value

play04:42

is proper so I could say console.log and

play04:45

I could say

play04:46

value and I could print out my value so

play04:49

now hopefully I can see if my value is

play04:51

being passed in properly as you can see

play04:53

here my value is high so at least I know

play04:55

that is working and this is going to be

play04:56

the most basic way of debugging a

play04:58

problem we're going to get to more

play04:59

Advanced versions later in the video so

play05:01

you can see okay my value is obviously

play05:03

correct so now I'm going to move on into

play05:04

my function to make sure that that is

play05:06

working properly so I can come inside of

play05:08

here to see okay is my value High here

play05:10

as you can see it's printing out High

play05:11

every single time so my value is still

play05:13

high and at that point I'm most likely

play05:15

going to realize oh I just forgot to

play05:17

change n to Value so that's where my

play05:19

problem is I'm going to change this to

play05:20

value and boom there's my problem

play05:22

nothing else to worry about rather

play05:23

straightforward so if you have a

play05:25

relatively simple bug or maybe a simpler

play05:27

function that you're having a hard time

play05:28

debugging just by reading it and looking

play05:30

at it throwing in a couple console log

play05:32

statements or other type of console

play05:34

statements in there to try to figure out

play05:36

exactly what's going on with your

play05:37

different variables is really important

play05:39

this is also great if you have a lot of

play05:41

if statements for example that are doing

play05:43

certain logic inside of them it's really

play05:45

great to put a console log inside of

play05:46

these because you can see okay did I hit

play05:49

this a lot of times I'll just put

play05:50

console log here and if I see that in my

play05:52

log okay I know that my code has made it

play05:54

to this point and then what I do is I

play05:56

take that console log and I move it down

play05:57

a little bit further in my code and I

play05:58

say okay am I getting to this point in

play06:00

my code and I save and I say okay it's

play06:02

printing out here so I'm getting to this

play06:03

point so I'll maybe move it down a

play06:04

little further and be like okay I'm

play06:05

still getting to this point in my code

play06:07

this is a great way to figure out how

play06:09

far your code is actually getting at a

play06:10

rather simple situation I use this all

play06:12

the time when I'm doing really simple

play06:14

debugging so using console log

play06:15

statements to figure out where your code

play06:17

is actually executing as well as

play06:18

figuring out what the values of your

play06:19

variables are is a great way to do

play06:21

really simple debugging but obviously if

play06:23

you get to more complicated problems

play06:24

this console log system is not really

play06:26

the best option because it really

play06:27

clutters up your console and it can be

play06:29

difficult to actually debug more

play06:31

complicated problems and that's where it

play06:32

comes in to start using an actual proper

play06:35

debugger now this is something that's

play06:36

really cool I'm going to show you

play06:38

exactly what this does all you do is

play06:39

anywhere inside of your code just type

play06:41

in the word debugger just like that you

play06:43

can see it turned blue because this is a

play06:45

JavaScript keyword and now when I save

play06:47

and rerun my code immediately I'll

play06:49

expand this so it's a little bit easier

play06:50

to see you can see I get this huge

play06:51

section on the right hand side here if

play06:53

you're inside of Chrome for the dev

play06:55

tools you can see it opens up this

play06:56

sources Tab and the sources tab shows

play06:58

you exactly all your JavaScript code so

play07:00

this is all the JavaScript code that

play07:01

I've written over here on the left you

play07:03

can see it's repeated on the right here

play07:05

it's paused my code exactly on this

play07:06

debugger line so I can see the value of

play07:08

every variable I have for example I can

play07:10

see the value of N I can see the value

play07:12

of my value variable I can hover over

play07:13

things inside of the code and it tells

play07:15

me the exact value of those variables

play07:17

and the really nice thing is you can see

play07:19

right here I have these buttons that

play07:20

allow me to actually do different things

play07:22

with my code so this very first button

play07:24

right here all it does is just resume

play07:26

execution it essentially unpauses my

play07:28

code and it'll run all the way until I

play07:30

reach the next debugger statement or

play07:32

until my program is done so if I click

play07:34

this you can see nothing at all happens

play07:36

my code just runs perfectly fine and

play07:37

prints out everything just like it did

play07:39

before now let's rerun our code by

play07:41

Saving to get back to this point the

play07:42

next thing that I have is going to be

play07:44

called step over then we have step in

play07:47

and we have step out these are kind of

play07:49

really important things to look at so by

play07:51

using step in it essentially allows me

play07:52

to step into whatever thing I'm calling

play07:55

it's going to be a function usually so

play07:56

if I click on step in it's going to step

play07:58

in to the thing that I'm doing so if I

play08:00

keep clicking step in you can see it's

play08:02

constantly stepping into what I have

play08:04

right here I'm not actually running any

play08:05

functions so there's not really anything

play08:07

that's happening when I do step in but

play08:09

if I were to move my debugger statement

play08:10

I'm just going to expand this so I can

play08:11

show you what I'm talking about I'm

play08:12

going to move it right here before I

play08:14

call these functions now if I move over

play08:16

to here and I just resume my script you

play08:18

can see we're now stuck at this debugger

play08:19

statement if I use this step over

play08:22

function what it does is it steps over

play08:24

this function it does not actually step

play08:25

into the function instead the next time

play08:27

it pauses is going to be my next line of

play08:29

code so you can see it pauses right here

play08:31

for my next line of code while if I

play08:33

click step into that's going to go into

play08:35

the function and pause on the very first

play08:37

line so you can see I click step into

play08:38

and now I'm on the very first line of

play08:40

that function and it's going to be

play08:41

executing that code now you can see I

play08:43

have quite a bit of stuff going on

play08:44

inside here I would have to click this

play08:46

step into function a lot of times to get

play08:48

all the way through this whole Loop and

play08:49

this whole function that's where the

play08:51

step out function comes in if I click on

play08:53

this it's just going to take me

play08:54

essentially to the very next line after

play08:56

that function is called this is a really

play08:57

great way to be stepping into code and

play08:59

as soon as you get to the point where

play09:00

you're like okay I don't care anymore

play09:02

about this function click step out and

play09:03

it's going to bring you to the very next

play09:05

line directly after that function is

play09:06

called now the final option that we have

play09:08

for these buttons is going to be this

play09:09

button just called step and this works

play09:12

almost identical to the step into

play09:14

function but it works slightly

play09:15

differently when you're dealing with

play09:16

asynchronous code so let's go ahead and

play09:18

actually change our code slightly to

play09:20

show you what I'm talking about I'm just

play09:21

going to go in here and I'm going to add

play09:23

a set

play09:24

timeout there we go this set timeout is

play09:26

going to last 1 second and we'll just

play09:28

say console. log time there we go super

play09:31

straightforward stuff that's going on

play09:32

here I have my debugger directly above

play09:34

it so if I just resume and rerun my code

play09:36

you can see I'm at that debugger right

play09:38

there now if I use the step into

play09:40

function my code is actually going to

play09:42

wait when I'm on this set timeout it's

play09:43

going to wait a full second and then

play09:45

it's going to put my debugger directly

play09:48

inside that set timeout because it's now

play09:50

trying to step into that asynchronous

play09:52

set timeout code so if I use step into

play09:54

it's going to wait and then step into

play09:56

that set timeout function now if I

play09:58

resume and refresh my code back at that

play10:00

breakpoint and I use the step function

play10:02

instead that's going to go in the normal

play10:04

chronological order so my set timeout is

play10:06

not done yet so if I click this you can

play10:07

see it's going to print name click it

play10:09

again and it's stepping into my print

play10:11

name function let's step out of that

play10:12

here we're on print end times we can

play10:14

step over and so on so the only

play10:16

difference between these two is how it

play10:17

works with asynchronous code if you use

play10:20

step it's going to just execute in the

play10:21

normal execution order while if you step

play10:24

into your code's going to wait for that

play10:25

asynchronous code to finish before it

play10:27

jumps inside of it to look at that code

play10:29

this this is a fairly Niche thing that

play10:30

you don't have to worry about too much

play10:32

but it's nice to know the difference

play10:33

between the two now that's the basics of

play10:35

using this debugger command but there's

play10:36

a lot of other stuff you can do with the

play10:38

Chrome debugger and we're going to later

play10:40

show you how you can actually do this

play10:42

directly in vs code which is my

play10:43

preferred way to do more advanced

play10:45

debugging setups but as you can see here

play10:47

on this left hand panel besides all

play10:48

these buttons that I have at the top

play10:50

this last button here just disables all

play10:51

the break points that I have we don't

play10:52

really have to worry about that too much

play10:54

but as you can see here I have this

play10:55

breakpoint section so for example I can

play10:57

pause on any uncaught exception this is

play10:59

a really powerful thing if you have

play11:00

certain errors in your code but you're

play11:02

not really sure where they're happening

play11:03

for example if I were to spell first

play11:05

name incorrectly again and I Sav my code

play11:07

I'm going to get rid of this debugger

play11:09

statement and just refresh our code to

play11:10

exactly what we had before give it a

play11:12

quick save and you notice since I have

play11:14

pause on uncaught exception checked that

play11:16

means anytime I have an error in my code

play11:18

that I don't explicitly handle it's

play11:20

going to stop my code execution right

play11:22

where that error is show me what the

play11:24

error is show me the line where the

play11:25

error code the exact place where the

play11:27

error occurred this is a really easy way

play11:29

to track down specific error messages

play11:31

that you have and you can see inside

play11:32

this section that has the scope that

play11:34

tells me all the different variables

play11:35

that I have you can see I have my first

play11:36

name my last name my entire Global scope

play11:38

here which doesn't really matter too

play11:39

much as well as all the information on

play11:41

the actual error that is occurring tons

play11:43

of really useful information inside of

play11:45

there so I love having this checked

play11:46

pretty much anytime that I'm working

play11:48

inside a code where I have errors that

play11:49

are happening and I'm not really sure

play11:50

where they're coming from now there's

play11:52

also an additional checkbox for pause on

play11:54

cot exceptions this essentially just

play11:56

means anytime you properly handle an

play11:58

error with like a a try catch statement

play12:00

or a catch for a promise then it's going

play12:02

to also pause your execution in those

play12:04

scenarios I recommend generally not

play12:06

turning this on because it's going to

play12:07

give you so many false positives of

play12:09

errors that are properly handled by

play12:10

things like Library code you use and so

play12:12

on that it's just overwhelming with

play12:14

errors and stuff that's pausing that you

play12:15

don't actually care about and doesn't

play12:17

usually help you with your debugging

play12:19

code but I do recommend keeping pause on

play12:21

uncut exception on in many cases because

play12:23

it makes it easy to find where there's

play12:24

errors inside of your code now if I just

play12:26

continue the execution of my code make

play12:27

this a little bit larger so it's easier

play12:29

to see everything you can see the next

play12:30

section is this call stack now all the

play12:32

call stack is is just going to show you

play12:34

all the functions that are currently

play12:35

being called in the order that they are

play12:37

called in so in our particular code

play12:39

let's modify it a little bit so we have

play12:41

a function called Main and inside that

play12:43

function that's called main we're going

play12:44

to call Print name and maybe inside of

play12:46

here we're also going to call another

play12:48

function so we're going to say function

play12:49

test just like that and inside this

play12:51

function we're going to call Print n

play12:54

times we're going to print out two times

play12:56

the text of by sure and in here will

play12:59

call test as well so we have all these

play13:02

different functions in this particular

play13:03

order so I'm going to give that a quick

play13:05

save and what I want to do is I want to

play13:06

load up my debugger inside my print end

play13:09

times so I'm just going to come in here

play13:10

debugger just like that give it a quick

play13:12

save and now we'll move over here now in

play13:14

my particular code I'm calling this

play13:16

function twice I'm calling it once right

play13:17

here and once inside test so it can be

play13:19

kind of hard to tell which particular

play13:21

scenario I've run into where have I

play13:23

actually called this code that's where

play13:24

the call Stat comes in you can see here

play13:26

it has print end times and then if I

play13:28

click the next level it is anonymous and

play13:30

it actually shows me the exact line of

play13:31

code where this has been called now the

play13:33

reason this is labeled as Anonymous is

play13:35

just because it's something that's in

play13:37

the main portion of my file as you can

play13:38

see on my actual code it's just at the

play13:41

top level of my file so it's essentially

play13:42

inside of an anonymous function you'll

play13:44

also see this anytime you use functions

play13:46

that don't have names so most of the

play13:48

time you're going to see those with

play13:49

arrow functions now if we continue our

play13:52

execution to the next time that print

play13:53

end times is going to be called you'll

play13:55

see that our script actually finished

play13:56

that's cuz I should make sure that I

play13:57

call Main that it actually works so now

play14:00

here we're on our first time we called

play14:01

it if I click next you can now see that

play14:03

it's throwing an error on first name so

play14:05

let me fix that first there we go so now

play14:07

I can continue the execution we're

play14:09

inside of the print name the first time

play14:10

now we're inside print name the second

play14:12

time or print end time sorry and you can

play14:14

see here our call stack is much larger

play14:16

we have our print end times function we

play14:17

have our test function so if I bring

play14:18

this down a little bit and click you can

play14:20

see we're inside that test function

play14:21

right here if I click on Main you can

play14:23

see that this is where we called it

play14:25

inside of our main function and if I

play14:26

click Anonymous you can see that that's

play14:27

where we called our main function

play14:29

so being able to go through the call

play14:31

stack level by level is really great CU

play14:33

not only can you tell where you've

play14:34

actually called this function but also

play14:35

it'll tell you the exact scoping of all

play14:37

your different variables at each level

play14:39

of the call stack so inside my test

play14:41

function this is all the different scope

play14:43

that I have inside main you can see I

play14:45

have a separate level of scope inside my

play14:47

Anonymous another level of scope and

play14:48

inside print end times another level of

play14:50

scope it tells me exactly what each of

play14:52

the different variables are inside of

play14:53

every single section which is really

play14:55

nice now if we can continue on from here

play14:57

the next thing I'm going to be talking

play14:58

about are break points as you can see

play14:59

every single one of these categories is

play15:01

breakpoints the most simple form of

play15:04

breakpoint actually falls under this

play15:05

breakpoints category and that's because

play15:07

anywhere in your code you can add a

play15:08

breakpoint and to do that inside of the

play15:10

Chrome debugger all you do is just click

play15:12

on the line number what that's going to

play15:13

do is add a breakpoint so let's say I

play15:15

want to add a breakpoint right here on

play15:16

line number nine you can see in this

play15:18

breakpoint section it's telling me the

play15:20

exact script file where this is what the

play15:21

line is and what the code is and now I

play15:23

can even remove this debugger statement

play15:25

completely give this a save and I can

play15:27

move around exactly where my breakpoint

play15:29

is going to be so it's on that four

play15:30

statement and you can see essentially

play15:32

when I run my code it's going to stop

play15:34

right where I specified this particular

play15:36

breakpoint so again if I save my code

play15:38

you can see it stopping right there so

play15:39

this is a really easy way to actually be

play15:41

able to put a breakpoint directly in

play15:42

your code and stop where you want to

play15:44

without adding the debugger statement

play15:46

into your source code this is really

play15:47

great if you have code you can't easily

play15:49

change for example you're on a

play15:50

production version of your site and you

play15:52

want to test a particular problem why

play15:54

it's happening you want to debug it

play15:55

adding in these different break points

play15:57

is a really great way to do that another

play15:59

nice thing about breakpoints is you can

play16:00

really easily disable them or you can

play16:02

completely remove them by clicking on

play16:03

the line number again now let's just let

play16:05

our code finish out and we'll talk about

play16:06

this xhr fetch breakpoints essentially

play16:09

this works anytime that you have a fetch

play16:11

request inside your code that's fetching

play16:12

out to another URL for example anytime I

play16:15

have example.com inside of a URL it's

play16:17

going to break inside of that fetch

play16:19

statement for me this is a great way to

play16:21

be able to say hey you know what I know

play16:22

I'm fetching a particular URL I don't

play16:24

know where the code is for that fetch

play16:25

statement but I want to add a breakpoint

play16:27

so that anytime I make a fetch statement

play16:29

to example.com it's going to put a

play16:31

breakpoint directly inside that fetch

play16:33

statement it's a really handy way to do

play16:34

that for now we're just going to remove

play16:35

that cuz we don't have any fetch

play16:37

statements another thing you can see

play16:38

here I'm going to skip a little bit down

play16:39

is the event listener breakpoints as you

play16:41

can see I can go through and I can do

play16:43

any particular event that I want I can

play16:45

actually make sure I do exactly what I

play16:46

want for example in my mouse I can say

play16:48

anytime I have a click event listener I

play16:50

want to actually pause inside that click

play16:52

event listener whenever I do the click

play16:54

so if I open up my Google Chrome and I

play16:55

just click inside of here immediately in

play16:58

my debugger you can see it's gone inside

play17:00

of that document. add event listener

play17:01

this is my click event listener and it

play17:03

stopped on the very first line and

play17:05

that's how these event listener break

play17:07

points work you can essentially say

play17:08

anytime a particular event occurs I want

play17:10

to break inside the exact code that's

play17:12

listening for that event which is a

play17:13

great way to be like you know what I

play17:15

think something's happening on Mouse

play17:16

click but I don't know which particular

play17:18

event it is or where the event is in my

play17:20

code I can just come in here and say you

play17:21

know what every single click event in my

play17:23

code it's going to throw a breakpoint

play17:24

directly into them for me automatically

play17:26

and we can close out of that let our

play17:28

code continue on and we can look at this

play17:29

Dom breakpoints section this Dom

play17:31

breakpoints is actually something you

play17:32

set inside the elements tab here so for

play17:34

example inside of my body I could write

play17:36

click this and I can come to the section

play17:38

for adding a breakpoint where it says

play17:40

break on and there's three options

play17:41

there's going to be node removal so

play17:43

essentially when this thing is removed

play17:45

attribute modification for example if I

play17:47

change the class name if I change other

play17:49

things like the title element or I

play17:50

change the actual attribute for like a

play17:52

data set property and then finally we

play17:54

have subtree modification that means we

play17:56

added children modified the children

play17:57

removed children Essen changed anything

play17:59

inside the element so we can actually do

play18:01

a breakpoint on these different things

play18:03

which is great to say you know what I

play18:04

want to do something whenever this

play18:05

particular element is removed and now

play18:07

anywhere in my code as soon as this

play18:09

element is removed it's going to pause

play18:10

me on the exact line of code that

play18:12

removed that element or if I wanted to

play18:14

have a breakpoint that's happening

play18:15

anytime things are modified it's going

play18:16

to pause directly anytime I try to

play18:18

modify this body so we can actually see

play18:20

that really easily I can come into my

play18:22

code

play18:23

document.body do

play18:25

classlist do add and I'm just going to

play18:28

add the class of High super

play18:29

straightforward and simple and since we

play18:31

have inside of here that we're breaking

play18:33

on that attribute modification and the

play18:35

subre modification we actually can make

play18:37

this a little bit easier by just

play18:38

appending a child so we can just say

play18:40

we'll just append the text High to the

play18:41

very end here inside of our body you can

play18:43

see that's being appended right there

play18:45

and to make sure that we're able to link

play18:46

this up properly let's just move that

play18:47

inside of our click event listener so

play18:49

inside of our click event listener we're

play18:50

going to pending directly into our body

play18:53

element so now what we can do is we can

play18:55

open up our Chrome browser and I can

play18:57

just click inside of here and you can

play18:58

see immediately my code has paused and

play19:00

gone to the exact line where I changed

play19:03

my body and you can see paused on sube

play19:05

modification for me appending something

play19:07

into that body element this is a really

play19:09

cool thing that I absolutely love about

play19:11

debugging inside of Chrome or Firefox or

play19:13

any other debugger is it makes it really

play19:15

easy to check when things are changing

play19:16

inside of the Dom so let's just let that

play19:18

code finish out as you can see here all

play19:20

of our different Dom breakpoints are

play19:21

being listed the next thing we have is

play19:23

going to be Global listeners we don't

play19:25

really have to worry too much about what

play19:27

these Global listeners are but these are

play19:28

ESS enally listeners that are set up on

play19:30

the window object or other Global

play19:31

objects I can actually see this a little

play19:33

bit more in action if I just come in

play19:34

here and I add an event listener on my

play19:36

window so we'll just add a resize event

play19:38

listener for example doesn't even matter

play19:40

what the code inside of here does now

play19:42

you can see we have that resize event

play19:44

listener and I can click on it and

play19:45

brings me to the exact line where that

play19:46

is so it's an easy way to see things

play19:48

that are happening on the exact Global

play19:49

scope then finally we have this CSP

play19:52

violation breakpoints now this one is a

play19:54

little bit interesting it stands for

play19:56

Content security policy and essentially

play19:58

if you have a Content security policy

play20:00

set up for your site this is going to be

play20:02

able to detect the errors that are being

play20:04

thrown and you can actually break on

play20:05

those particular errors inside your code

play20:07

to see exactly what lines they are I

play20:09

don't have any content security policy

play20:11

set up for this it's something that

play20:12

you're going to see a lot more in like

play20:13

larger sites and larger teams so for the

play20:15

most part you probably don't need to

play20:16

worry about this particular option but

play20:18

the other options inside here are all

play20:20

incredibly useful now the final thing I

play20:21

want to talk about with this particular

play20:23

page of the Chrome debugger is the watch

play20:25

tab so right next to scope we have this

play20:27

watch Tab and inside here I can click

play20:29

the plus button and just typee in any

play20:30

variable name that I want for example I

play20:32

can type in first name just like that

play20:35

and now what's going to happen I'll just

play20:36

move my camera out of the way real quick

play20:38

you can see that essentially it's going

play20:39

to give me the value of the first name

play20:41

variable anywhere inside of my code

play20:43

wherever I am so if I put a debugger

play20:45

statement for example inside of here

play20:48

there we go got a debugger come over to

play20:50

here and I refresh my code you can see

play20:53

make sure I get rid of that pause on COD

play20:54

exception that first name right here if

play20:56

I hover over this is set to Kyle because

play20:58

inside this code first name is Kyle now

play21:00

this watch section I don't use super

play21:02

often but it's really useful if you want

play21:03

to kind of track a variable through an

play21:05

entire set of code like maybe you have a

play21:07

really large function and you have one

play21:08

variable that's changing a lot this is a

play21:10

great way to write out what that

play21:11

variable is but you don't have to just

play21:13

write out a single variable for example

play21:14

I can write out my own JavaScript

play21:16

expressions for example first name and

play21:18

last name combined together and you can

play21:20

see it's printing out Kyle Cook as the

play21:21

value for that particular code so this

play21:23

is a really great way if you want to

play21:24

have more complicated things where you

play21:26

check the value of certain variables or

play21:28

check like certain if statement values

play21:29

things like that are really good for

play21:31

this watch section but I generally find

play21:32

myself I don't use it too much because I

play21:34

can just use this scoping section to get

play21:36

all the exact same information now I'm

play21:38

going to come back to this chrome

play21:39

debugger in a little bit because I want

play21:41

to talk about some of the other tabs

play21:42

like the network tab which is incredibly

play21:44

useful but I also want to show you how

play21:45

you can actually take all these powers

play21:47

that you have in the Chrome debugger and

play21:49

get them directly inside a visual studio

play21:51

code I'm going to completely exit out of

play21:53

that we're going to open up full screen

play21:54

for visual studio code and I want to

play21:56

show you how you can debug everything

play21:57

directly inside of here which is a much

play21:59

nicer debugging experience because you

play22:01

have your full code editor work with and

play22:02

all the code is showing up directly

play22:04

inside of here so the very first thing

play22:06

that we need to do is we need to go to

play22:07

this tab right here called run and debug

play22:09

it should be the option essentially

play22:11

almost at the very bottom so if we open

play22:12

up run and debug you can see I have this

play22:14

run and debug Command right here and I

play22:15

want to click on that and for my

play22:17

particular use case I'm using Chrome so

play22:19

I'm going to click web app in Chrome

play22:20

because I'm creating a web application

play22:22

for Chrome if you're doing node.js

play22:23

choose node.js and so on and you can

play22:25

even create your own custom scripts but

play22:27

in our case this is going to do pretty

play22:28

much all the work for us now the first

play22:30

thing you need to put inside of here is

play22:31

the URL for where your actual site is

play22:33

running now in my particular case I'm

play22:35

using an extension called live server

play22:37

this live server sension just

play22:39

essentially lets me host HTML files so I

play22:41

can open them up and actually view them

play22:43

and it works on Port 5,500 so here I'm

play22:45

going to change Local Host to Local Host

play22:48

5500 just like that and now it's going

play22:50

to listen for that 5500 port and then

play22:53

all you need to do once you have that

play22:54

done is just go to that tab you can now

play22:56

see I have this play button right here

play22:57

I'm going to click that play button you

play22:59

can see on my screen it's actually

play23:00

opened up this chrome window right here

play23:03

and you can see at the top I have this

play23:05

little bar that I can use to pause I can

play23:07

step over step into step out of all

play23:09

those same things that we're used to and

play23:11

I can even restart my program from the

play23:12

beginning and then I can end this if I

play23:14

want to now this is really great because

play23:16

I can go into my script for example and

play23:18

I can add in a debugger

play23:20

statement oops debugger just like that

play23:23

if I can spell properly there we go give

play23:25

that a quick save and now immediately it

play23:27

has paused me on that line because my

play23:29

program automatically restarts when I

play23:30

save that's part of live server and on

play23:32

the left hand side it's a little bit

play23:34

small font unfortunately I'll zoom in a

play23:35

little bit so it might be slightly

play23:36

easier to see but you can see here I

play23:38

have all of my scoping all my different

play23:40

variables my Global scoping everything

play23:42

that I could possibly want to see about

play23:43

everything I have a watch section where

play23:45

I could for example watch particular

play23:47

variable names when I can even do

play23:48

expressions for example I can just copy

play23:50

this expression paste it into here and

play23:52

now you can see I get the combination of

play23:54

first name and last name I get the

play23:56

entire call stack showing up right here

play23:57

and I can jump to the exact lines where

play23:59

all those different things are being

play24:00

called if I minimize these values down a

play24:03

little bit you can see I have my whoops

play24:04

not my call stack my loaded scripts

play24:05

these are all the different scripts that

play24:07

are being currently loaded you can see I

play24:08

have all my break points with the exact

play24:10

same checkboxes and if I wanted to add a

play24:12

breakpoint all you need to do is just

play24:13

click off to the side here you can see

play24:15

this little red dot is going to appear

play24:16

off to the side just click on that and

play24:18

boom now we have a break point being

play24:19

added and we even have our event

play24:21

listener break points this is all pretty

play24:23

much identical to what we had when we

play24:24

were working inside of chrome I'm going

play24:26

to move my camera back to the corner

play24:27

just to keep it out of the way so you

play24:29

don't have to actually see it and what

play24:30

we can do a little bit fancier here than

play24:32

some of the other stuff that we could do

play24:33

in Chrome is if I just let this continue

play24:35

all the way through is we can actually

play24:36

add in fancy or debug breakpoints for

play24:39

example I can do a breakpoint like this

play24:40

and if I restart my program boom it's

play24:41

going to be right on that line pretty

play24:43

self-explanatory but I can also put in

play24:45

slightly more customized break points

play24:47

for example if I right click on this you

play24:48

can see I add a normal break point I can

play24:50

add a conditional breakpoint a log point

play24:52

which essentially just log something out

play24:53

in my console and then I have a

play24:55

triggered breakpoint which does

play24:56

something based on when other break

play24:57

points happen

play24:58

so for example let me add in a

play25:00

conditional break point and I can just

play25:01

say when I is equal to 2 so now this

play25:04

breako is only going to occur when I is

play25:07

equal to the value of two and if I

play25:09

restart my program and I check the value

play25:10

of I at this breakpoint you can see it

play25:12

is two and if I click to go to the next

play25:14

one the next one there is no next one

play25:16

because I'm only calling this function

play25:17

one particular time and actually I am

play25:19

calling this function twice you can see

play25:20

I'm calling print name with five print

play25:21

name with two but when I call it with

play25:23

two I never actually reaches the value

play25:25

of two it only reaches the value of 0

play25:27

and one and never gets the value of two

play25:29

which is why this break point is never

play25:30

hit a second time now you will notice

play25:32

one downside that it appears at first is

play25:34

that I can't see what my console output

play25:36

is but if I open up this section here

play25:39

that has your terminal you can go to the

play25:40

debug console and boom I get the exact

play25:42

same console output that I get inside of

play25:44

chrome but since I'm using my debugger

play25:46

nvs code I have that exact same

play25:48

information I can jump to the line

play25:49

numbers of where all this stuff is

play25:51

occurring so I get the exact same output

play25:53

that I would get inside of chrome but

play25:55

now I'm getting it directly inside of vs

play25:57

code which is really great for debugging

play25:58

now I'm going to minimize that just so

play26:00

it's not taking up a bunch of screen

play26:01

space and I want to show you what that

play26:02

log Point looks like if I just come in

play26:04

here I can just say that I want to log

play26:05

the value of I for example and now it's

play26:07

going to log me the value of I every

play26:09

single time this runs so if I do a

play26:10

refresh and I just expand past this open

play26:13

up the debug console you can see it's

play26:15

printing out I a bunch of times

play26:16

obviously I want this to print out the

play26:18

value of I so if I just put it in

play26:20

Brackets like this it'll actually use

play26:21

the variable itself so now if I refresh

play26:23

this and I make sure that I move that

play26:25

debugger to the correct point so I'm

play26:26

going to just remove this one I'm going

play26:28

to put on this line in particular so I'm

play26:30

going to just remove the break point

play26:31

that we have here add in a log Point

play26:33

logging out the value of I inside of

play26:35

here and now if I just let this continue

play26:36

all the way through you can see it's

play26:38

printing out zero one up here it's

play26:39

printing out all the way up to four it's

play26:41

essentially just counting all the way up

play26:42

for me I'm going to be honest I don't

play26:44

use this particularly often just because

play26:46

I can throw in a console log statement

play26:48

relatively easily but this is nice if

play26:49

you need to add in a particular thing

play26:51

inside your code to log something

play26:52

without mudding it up with a bunch of

play26:54

console log statements so now I want to

play26:56

talk about this triggered breakpoint

play26:58

section so again I'm going to minimize

play26:59

this so what I'm going to do real quick

play27:01

inside of my code to demo this is I'm

play27:02

going to add an if statement if n is

play27:04

greater than three then I just want to

play27:07

console log big doesn't really matter

play27:10

what I'm doing here I'm going to add a

play27:11

breakpoint on that line now you notice

play27:13

this breakpoints hollowed out

play27:14

essentially it's saying that this is

play27:15

unverified my file has been modified I

play27:17

need to restart my debugging session so

play27:19

if I just save this and I make sure I

play27:21

restart it'll make sure that that actual

play27:22

debug statement works properly now here

play27:24

I'm going to add a triggered breakpoint

play27:26

I'm going to say I want to wait for a

play27:27

particular break point I want to wait

play27:28

for the break point on this particular

play27:30

line script line 8 and I'm going to

play27:32

click okay so now this line of code will

play27:34

wait for this particular break point to

play27:36

be hit before it actually runs this

play27:38

breakpoint here so if I restart you can

play27:40

see this breakpoint has been hit which

play27:42

means I'm also hitting my breakpoint

play27:43

here all of that is working perfectly

play27:45

fine now I'm going to remove both of

play27:47

these break points just so I can get my

play27:48

code back to a state that I had before

play27:50

and now what I'm going to do is I'm

play27:51

going to change this to be greater than

play27:53

30 this is never going to get hit so I'm

play27:54

going to add this break point in I'm

play27:56

going to add a conditional or not

play27:57

conditional I'm sorry I'm going to add a

play27:58

weit for breakpoint here for that

play28:00

particular line click okay and now if I

play28:02

restart my code you'll notice that I'm

play28:04

never hitting this breakpoint and that's

play28:06

because I never have an n greater than

play28:08

30 which means this breakpoint never

play28:10

actually executes and since this

play28:11

breakpoint never executes it never

play28:13

executes this breakpoint down here now

play28:15

this is a rather Niche thing that you

play28:17

may want to use but it's really nice

play28:18

where if you have an if statement then

play28:20

you only want to check for certain

play28:22

things happening if that if statement

play28:23

evaluates to true or if certain code

play28:25

runs this is a great way to make sure

play28:26

you stop your execution of your program

play28:28

only if certain prerequisites are met

play28:30

inside of your code this is essentially

play28:32

also how those triggered breakpoints

play28:34

work if we were to edit this and do a

play28:36

hit count for example like only do this

play28:38

when I've hit this a certain amount of

play28:39

times so like for example two I have to

play28:40

hit this breakpoint twice before it

play28:42

actually finishes or based on when a

play28:43

certain expression evaluates the true we

play28:45

kind of already looked at that as well

play28:47

so these are really great ways to only

play28:49

breako on certain particular situations

play28:51

now pretty much the only thing that you

play28:53

may notice that is slightly different

play28:54

inside VSS code versus Chrome is I can't

play28:57

add a debugger state on fetch statements

play28:59

but that's actually something I can do

play29:01

there's just no UI for it so if I hit

play29:02

control shift p and I search for fetch

play29:05

you can see I have edit add and remove

play29:07

for a fetch breakpoint if I click on

play29:09

that I can type in a URL and any URL

play29:11

that I fetch that is contained inside

play29:13

here for example if I did example.com

play29:15

and I hit enter that's going to

play29:17

essentially set up a particular fetch

play29:19

breakpoint for anytime I fetch

play29:21

example.com so you have all that

play29:23

functionality that's built into Chrome

play29:24

directly built into vs code and this is

play29:26

my preferred way to debug especially on

play29:28

larger projects now the final thing that

play29:30

I want to talk about is going to be a

play29:31

few more tabs inside of chrome so let's

play29:33

just open up that Chrome debugger that

play29:35

we had

play29:36

before there we go got that open I'm

play29:38

just going to remove all these different

play29:39

break points I don't actually need all

play29:41

these break points so let's just make

play29:42

sure we get rid of all of

play29:44

these there we go just so we don't have

play29:46

weird break points showing up so and

play29:48

we're going to go to the network tab

play29:49

here this is probably the next most

play29:50

powerful tab after the console the

play29:52

sources Tab and the elements tab because

play29:54

this allows you to see exactly what's

play29:56

being fetched every single time you

play29:57

actually fetch from your page so what we

play29:59

can do I'm just going to put this off to

play30:00

one side and on the other side I'm going

play30:02

to have my document so I'm going to

play30:04

bring up my network tab make it as large

play30:05

as possible and in my sources section

play30:07

I'm just going to make sure I remove all

play30:08

break points I'm going to click this to

play30:09

remove all the break points this

play30:11

essentially just disables all my break

play30:12

points so now we're on the network Tab

play30:14

and you can see inside of here when I

play30:15

refresh my page it shows me everything

play30:17

that's fetched so I'm going to clear

play30:18

this click refresh and now you can see

play30:20

exactly every single thing on my page

play30:21

that is being fetched this is really

play30:23

simple for me I have an HTML page I have

play30:25

a script page and since I'm using live

play30:26

server there's a wed so connection so

play30:28

when I save a file it automatically

play30:30

refreshes also you can see here I get

play30:32

this like waterfall that shows me

play30:34

exactly what's going on how long every

play30:36

single request takes and so on I get all

play30:38

the different headers response timings

play30:39

previews and so on which is really

play30:41

important to debug exactly what's

play30:42

happening for certain things now it can

play30:44

be hard to narrow down exactly what you

play30:46

need because large sites are going to be

play30:47

downloading hundreds and hundreds of

play30:49

different files which is why you can

play30:50

come in here and do only fetch request

play30:52

for example or only things that are

play30:54

documents maybe you only want to check

play30:55

things that are CSS JS fonts images so

play30:57

on media you know you can pretty much

play31:00

click around here to get exactly what

play31:01

you want to be narrowing down your

play31:03

search too also if I just do a refresh

play31:05

again on this you can search for certain

play31:07

things so if I go back to all and I

play31:08

search for

play31:10

script.js you can see essentially it's

play31:11

giving me only the things that match

play31:13

that script.js now unfortunately this

play31:15

isn't being super accurate right now

play31:17

with the actual things that are being

play31:18

showing up inside of this when I like

play31:19

for example search for script.js there's

play31:22

just a little bit of bugginess going on

play31:23

inside here I think it's because of how

play31:24

zoomed in I have my browser and other

play31:26

stuff that's going on but normally these

play31:28

different elements for index HTML and

play31:30

websocket those actually wouldn't show

play31:31

up now another really great thing about

play31:33

this tab that I absolutely love we just

play31:35

bring it back to essentially normal is

play31:36

we have the ability to disable and

play31:38

enable in caching I recommend having

play31:40

disable cache always checked when you're

play31:41

doing this that way you can really test

play31:43

everything at the most optimal state to

play31:45

make sure you don't have any caching

play31:46

problems giving you issues it's going to

play31:48

make sure it always fetches everything

play31:49

for you also you can throttle to make

play31:51

your page slower for example fast 3G if

play31:53

I were to refresh it's not going to take

play31:55

much longer to actually download all the

play31:56

different files that I need my page is

play31:58

relatively small I mean it's almost

play32:00

completely empty but still if you had a

play32:02

larger page you can see that this is

play32:03

going to drastically slow things down

play32:04

for those different testing purposes now

play32:06

the next tab I want to take a look at

play32:07

real quickly is the performance tab I'm

play32:09

not going to go super in-depth into

play32:10

everything inside of here but

play32:11

essentially the main thing is you just

play32:13

want to click this record button right

play32:14

here this is going to start profiling do

play32:16

whatever you want to do click some

play32:17

buttons whatever it is I'm just going to

play32:19

do a full refresh my page doesn't really

play32:20

matter and then you just click stop and

play32:22

what's going to happen is it's going to

play32:23

break down exactly how long every single

play32:26

step of your entire process took for

play32:27

every single thing that happened so this

play32:29

is a great way for you to be like okay

play32:30

what are the different things that are

play32:31

slowing me down for example scripting

play32:33

was by far the slowest thing in my

play32:34

application obviously in my particular

play32:36

application there's almost nothing going

play32:38

on so that's why there's pretty much no

play32:40

values showing up inside of here but if

play32:41

you had a more complicated application

play32:43

you can look at okay how long is certain

play32:44

things like the Dom content loaded event

play32:46

happening how long does it take for on

play32:47

load how long does each frame take to

play32:49

load like how long is every single

play32:50

function inside of my thing taking it

play32:52

gives you a bunch of different

play32:53

information I get like a call tree and

play32:54

show on it's really really useful for

play32:56

the most part though I don't mess with

play32:57

this page too much unless I have

play32:59

particular performance issues and I'm

play33:00

having a hard time figuring out exactly

play33:02

where they are this can give you some

play33:03

Clues to look into the right places now

play33:05

the next few tabs I want to talk about

play33:06

this application tab this one's really

play33:08

useful for figuring out what values you

play33:10

have in local storage for example maybe

play33:12

things inside a session storage and

play33:13

inside of your cookies it's a great way

play33:15

to kind of debug that information even

play33:16

the index DB you can look at all that

play33:18

stuff you can change things delete

play33:20

things for example I can add a new value

play33:21

inside of here if I wanted to it really

play33:23

doesn't matter it's really great to be

play33:24

able to just kind of go in and figure

play33:25

out okay what's happening inside of all

play33:27

this information the final thing I want

play33:28

to kind of talk about is this Lighthouse

play33:30

tab this is a really great tab for just

play33:31

being able to check different

play33:32

performance categories so I can like

play33:34

toggle on performance best practice SEO

play33:36

whatever I want to toggle click analyze

play33:37

page load and that's going to go through

play33:39

it's going to load up my page and a

play33:40

bunch of different things and it's going

play33:42

to tell me hey what were the slowest

play33:43

things to load what are things that are

play33:45

within acceptable parameters where are

play33:46

some accessibility things that I could

play33:48

fix and so on it's just going to give me

play33:49

a bunch of information on different

play33:50

things that I could fix inside of my

play33:52

site now it takes a little while to run

play33:54

and for my particular site we're pretty

play33:55

much going to get no useful information

play33:58

just because my site is completely blank

play33:59

and has nothing on it but if you have a

play34:01

larger site it's going to really help

play34:02

you with seeing what the different

play34:04

problems inside of your site are and

play34:06

this is a really great way so for

play34:07

example if you have like a lot of images

play34:08

that are taking a long time to load it's

play34:10

going to let you know about that and

play34:11

other things for example on my page you

play34:12

can see this page doesn't have anything

play34:14

on it it literally says right here

play34:15

there's nothing on your page so

play34:17

obviously there's nothing to actually

play34:18

talk about but if your page had more

play34:20

information it would give you a score

play34:22

between 0 and 100 telling you how good

play34:24

you were at these things and then it's

play34:25

going to give you a bunch of different

play34:26

warnings and errors down here for the

play34:27

the exact things that you're missing

play34:29

inside of it that you can fix and that

play34:31

is literally everything you need to know

play34:33

about debugging if you enjoyed this

play34:35

video I highly recommend checking out my

play34:37

JavaScript simplified course because I

play34:38

take complicated JavaScript Concepts

play34:40

like this and simplify them down into

play34:42

ways that are really easy to understand

play34:43

no matter what skill level you're at so

play34:45

if you want to really Master JavaScript

play34:47

and be able to build projects on your

play34:48

own I highly recommend checking out that

play34:50

course I'll link it down in the

play34:51

description for you with that said thank

play34:53

you very much for watching and have a

play34:54

good day

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Web DevelopmentDebugging GuideJavaScriptCoding SkillsError HandlingDeveloper ToolsCode OptimizationPerformance TipsVS CodeChrome DevTools