<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: sesamechicken</title>
    <description>The latest articles on DEV Community by sesamechicken (@sesamechicken).</description>
    <link>https://dev.to/sesamechicken</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F254641%2F6a055ba7-bab4-47da-9a4a-1d743c992802.png</url>
      <title>DEV Community: sesamechicken</title>
      <link>https://dev.to/sesamechicken</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sesamechicken"/>
    <language>en</language>
    <item>
      <title>Breakpoints: Not just for nerds! 🤓</title>
      <dc:creator>sesamechicken</dc:creator>
      <pubDate>Fri, 13 Nov 2020 20:37:18 +0000</pubDate>
      <link>https://dev.to/sesamechicken/breakpoints-not-just-for-nerds-58ok</link>
      <guid>https://dev.to/sesamechicken/breakpoints-not-just-for-nerds-58ok</guid>
      <description>&lt;p&gt;It's common to use &lt;code&gt;console.log&lt;/code&gt; in your code as a quick way to 'debug' and determine the value of a variable, or where and if a function is being called. It's straightforward and works the same way in every browser. It almost seems like a waste of time to use anything else. BUT, once you learn to use breakpoints and have an idea of what they can do, the &lt;code&gt;console.log&lt;/code&gt;'s &lt;strong&gt;&lt;em&gt;will be like acid in your eyes&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HHEpTiss--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8k8zsjfb5ga9wuh3l9ka.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HHEpTiss--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8k8zsjfb5ga9wuh3l9ka.jpg" alt="Radioactive Man hit with acid"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I want to keep this short, so here's a link to a live example so you can follow along: &lt;a href="https://sesamechicken.github.io/react-startup/"&gt;sesamechicken.github.io/react-startup&lt;/a&gt;, and the &lt;a href="https://github.com/sesamechicken/react-startup"&gt;repo for it here&lt;/a&gt;. I'm using Chrome for this, but you can use the browser of your choice.&lt;/p&gt;

&lt;p&gt;Our test code is a simple React app which shows 2 components - one that displays some witty text, and another connected component that will allow you to add items to your grandma's shopping list.&lt;/p&gt;

&lt;p&gt;Since you already &lt;code&gt;console.log&lt;/code&gt;, you know how to open the devtools, so let's do that now. Once open,  use &lt;code&gt;cmd + p&lt;/code&gt; to open the command palette so we can find the file we want to work with. In this case, we're using 'connected_component'.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---g9Ai_Ir--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f9bc7vdbdn76tm97jwga.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---g9Ai_Ir--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f9bc7vdbdn76tm97jwga.png" alt="The connected_component file in the source pane"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, let's look around for just a sec. There are two functions that actually &lt;em&gt;do&lt;/em&gt; things for us. &lt;code&gt;onKeyUp&lt;/code&gt; and &lt;code&gt;addListItem&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nx"&gt;onKeyUp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;persist&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;inputValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// A little overboard; I'm looking for the ENTER key&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyCode&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addListItem&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;addListItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;inputValue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addToList&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;addToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;inputValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In console-land, to see if our &lt;code&gt;onKeyUp&lt;/code&gt; method is firing properly and that we're getting the value we expect, we might do a little something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;onKeyUp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// We just added this&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="err"&gt;I fired! The value is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

    &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;persist&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;inputValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This seems reasonable. In fact, it is. &lt;em&gt;But&lt;/em&gt;, we can get the same info by not touching the code, and not waiting for a rebuild/re-render. Let's take a look...&lt;/p&gt;

&lt;h2&gt;
  
  
  Attain the same info by not touching the code, and not waiting for a rebuild/re-render.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ijfxm9un--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/npfqj2urduy8e4gisz3i.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ijfxm9un--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/npfqj2urduy8e4gisz3i.gif" alt="Adding the breakpoint in the devtools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Breakpoint (line-of-code)
&lt;/h3&gt;

&lt;p&gt;To add a breakpoint, we click in the margin next to the line we want to 'break' on, or, &lt;em&gt;pause script execution&lt;/em&gt;. When we type into the text input, the function fires and the browser halts at our breakpoint! Not only does it stop, but it provides us with all the information it has up until that moment. As you can see, we can see the value we're pulling off of &lt;code&gt;e.target&lt;/code&gt;, and, we can see the entire event passed to the method!&lt;/p&gt;

&lt;p&gt;This is the most basic breakpoint we can add and it covers &lt;em&gt;most&lt;/em&gt; use cases for &lt;code&gt;console.log&lt;/code&gt;. We have the info we wanted, we didn't touch the code, we didn't have to reload the page, and our tools didn't have to rebuild or re-bundle anything. 😀&lt;/p&gt;

&lt;p&gt;Once a breakpoint is reached, we need to instruct the browser to move on and continue script execution. We do this by clicking the Resume button in the dev tools or in the viewport.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ZVjx496--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/01d0otqdt27vkplj1cj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ZVjx496--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/01d0otqdt27vkplj1cj6.png" alt="Alt Text"&gt;&lt;/a&gt; or&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zVsGOZAS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jjya82vsu9254cf27oi9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zVsGOZAS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jjya82vsu9254cf27oi9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Logpoint
&lt;/h3&gt;

&lt;p&gt;Let's look at another type of breakpoint: &lt;strong&gt;logpoint&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;logpoint&lt;/code&gt; does exactly what you might think: it allows you to log any value you wish from the position you place it in the code into the console. Let's try it out.&lt;/p&gt;

&lt;p&gt;This time, let's play with the &lt;code&gt;addListItem&lt;/code&gt; method and select 'Add logpoint' on line #30. You'll notice a couple things that are different about this type of breakpoint. The first is that you can specify what to log out. The second is that the execution of the code won't stop when the browser reaches this breakpoint. Try adding 'value is: ' + this.state.inputValue. Now switch over to the console and add some items to your grandma's list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZegvXKCf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eqa2mh4vn77b015mszir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZegvXKCf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eqa2mh4vn77b015mszir.png" alt="Logpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conditional Breakpoint
&lt;/h3&gt;

&lt;p&gt;Building off of the last example, right click on your logpoint, and select 'Edit breakpoint.' Change the type from 'Logpoint' (via the dropdown above your text to log) to 'Conditional breakpoint' and enter the value: &lt;code&gt;this.state.inputValue === 'oranges'&lt;/code&gt;. Now, when you add items to the list, this breakpoint will watch the value. If it strictly equals 'oranges', it will stop and pause execution.&lt;/p&gt;

&lt;p&gt;There are other breakpoint types available to you, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fetch/XHR&lt;/li&gt;
&lt;li&gt;function&lt;/li&gt;
&lt;li&gt;DOM change/update&lt;/li&gt;
&lt;li&gt;event listener&lt;/li&gt;
&lt;li&gt;maybe more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you made it this far, I'd like to thank you for reading through my first technical post. I hope you learned something useful. Breakpoints are awesome when you know how to use them and how easy they are (plus you can debug a site that's in prod and not running locally!). If you have any advice or suggestions on how I may improve my writing or if this helped, please drop a note below!&lt;/p&gt;

&lt;p&gt;Keep coding! 🤠&lt;/p&gt;

&lt;p&gt;More reading:&lt;br&gt;
&lt;a href="https://developers.google.com/web/tools/chrome-devtools/javascript/breakpoints"&gt;https://developers.google.com/web/tools/chrome-devtools/javascript/breakpoints&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ux</category>
      <category>debugging</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
