Skip to content

Instantly share code, notes, and snippets.

@nrl240
Last active March 4, 2021 23:01
Show Gist options
  • Save nrl240/53975ab605b18918cadf7d3ce9582d8a to your computer and use it in GitHub Desktop.
Save nrl240/53975ab605b18918cadf7d3ce9582d8a to your computer and use it in GitHub Desktop.
Exit Ticket: Day 3 - Debugging, DOM

Exit Ticket: Day 3 - Debugging, DOM

You should be able to:

  • Be able to identify common ways to debug software and procedures to prevent bugs
  • Define the DOM
  • Manipulate the DOM using the DOM API
  • Explain how a browser uses HTML, CSS, and JavaScript to display a web page

What technique(s)/tools would you use to debug a program that crashes but gives you an error on a line that you didn't write (ie: from an external dependency)?

  • console.log / console.trace / console.error
    • In general
  • check your linter
    • Preventative measures
  • debugger
    • Issue: It can be useful, but it can also be in a piece of code you don't even recognize so you need to decide when to stop walking through functions you and your team didn't write.
  • comment out the program, then uncomment piece by piece util it crashes
    • A classic move
    • This is surprisingly useful if you know that everything worked before you added your batch of code. You can start commenting out certain sections to make sure individual pieces still work, and slowly add on more until it breaks.
  • read the stack trace
    • Less useful in this context, specifically
    • Since you didn't write this code, the stack trace won't necessarily help you. The only thing it can help is to possibly figure out what librarry you were using/where in a general location your broken code can be.
  • revert to a prior commit
    • Toss it in the bin and just start over.
    • Not really recommended.

Which of the following are true about the DOM? (Check all that apply)

True? Explanation (if applicable)
It is a tree ☑️ -
A single webpage can have any number of DOMs You can actually create a "new DOM" but there will always be one DOM that renders the page
It stands for: Document Object Model ☑️ -
It allows us to use JavaScript to manipulate the document content and structure ☑️ -
You cannot traverse the DOM from JavaScript, only through the browser's console -

How would you select the first instance of an <h1> tag in the DOM?

document.querySelector('h1')

  • Explanation: querySelector returns the first Element within the document that matches the specified selector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment