{"id":307,"date":"2019-06-21T23:23:29","date_gmt":"2019-06-21T23:23:29","guid":{"rendered":"https:\/\/www.regexseo.com\/blog\/?p=307"},"modified":"2023-02-07T16:32:10","modified_gmt":"2023-02-07T16:32:10","slug":"10-browser-console-hacks","status":"publish","type":"post","link":"https:\/\/www.regexseo.com\/blog\/10-browser-console-hacks\/","title":{"rendered":"10 Browser Console Hacks"},"content":{"rendered":"\n<p>Productivity in the workplace is always a major concern. We try all kinds of things to boost our productivity from using productivity apps like <a aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener nofollow\" href=\"https:\/\/asana.com\/\" target=\"_blank\">Asana,<\/a> <a aria-label=\"Brief (opens in a new tab)\" href=\"https:\/\/gobrief.com\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Brief<\/a> or using the <a href=\"https:\/\/www.snacknation.com\/blog\/increase-productivity-at-work\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">2-Minute rule<\/a>, to <a aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener nofollow\" href=\"https:\/\/www.flowers24hours.co.uk\/blog\/flowersandproductivity\/\" target=\"_blank\">bringing an entire garden to work<\/a>. So what about finding ways to improve our <a href=\"https:\/\/www.denierob.com\/blog\/5-tips-to-instantly-increase-your-productivity\" target=\"_blank\" rel=\"noreferrer noopener\">productivity<\/a> when we&#8217;re coding?<\/p>\n\n\n\n<p>If you\u2019re developing any kind of web-based project and your code isn\u2019t working as planned (which is most of the time) the first place you\u2019d check is your browser console.<br><\/p>\n\n\n\n<p>The console is arguably the most used tool that a developer uses to debug their code. Still, most developers just use it to search for syntax errors and console logging. While these two are the most common uses, that\u2019s just a fraction of what the console is capable of. <br><br>Here are 10 of the top browser console hacks that will make you (or your dev\u2019s) life much easier:<\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"706\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-571-2-1024x706.jpg\" alt=\"\" class=\"wp-image-1815\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-571-2-1024x706.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-571-2-300x207.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-571-2-768x529.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-571-2-435x300.jpg 435w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-571-2.jpg 1267w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>1.  Output errors using console.warning() &amp; console.error()<\/h2>\n\n\n\n<p>I bet you\u2019re using console log as a debugger for your web app projects. Typical <span style=\"background:lightgrey; font-style:italic\">console.log()<\/span> gets the job, but sometimes, when you use it too often, the important stuff can get lost in the giant output of every message type &#8211; from critical errors to standard reminders. A better way to output errors and warnings is to use <span style=\"background:lightgrey; font-style:italic\">console.warning()<\/span> and <span style=\"background:lightgrey; font-style:italic\">console.error()<\/span>. This will make higher priority issues stand out from the rest of the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/AoAYMTXzM9pxYEYePIOnRlvQcJVwcojC-DisUFDNZshvtoCv_Z6HRgywumQklFieMwZjsw0qW6GkhrNFCBaBKcEwxauBAVjYaK-xFwBPDR7DX2fcIVYz1iMu25JWL9qpKby36OFz\" alt=\"console.warning() &amp; console.error()\"\/><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"405\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-18-1024x405.jpg\" alt=\"\" class=\"wp-image-1816\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-18-1024x405.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-18-300x119.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-18-768x304.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-18-759x300.jpg 759w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-18.jpg 1313w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>2. Keep organized using console.group()<\/h2>\n\n\n\n<p>Sometimes when you\u2019re debugging statements within functions, you console log every stage of those functions. All of these console logs can get very unorganized. It gets hard to know where each of the logs came from. In these situations, it\u2019s a good choice to use <span style=\"background:lightgrey; font-style:italic\">console.group()<\/span>. This will group all of your logs into a group, that way it doesn\u2019t get mixed up with the rest of the logs.<br><br>Example: <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/XdfahJZTs__Xls97xEOhwRKSJzejoSWPycr24jm1HO7zJH9IHd7yxVP_pwSYNzLD69-GuKgrzVAR9WgRIdHamdmkmXeslb3FtOeMzjvU5cND8GLQpb5FmcqYTtPOlAC3rrIlXN_j\" alt=\"console.group()\"\/><\/figure>\n\n\n\n<p>Just using <span style=\"background:lightgrey; font-style:italic\">console.group()<\/span> will give you an uncollapsed view of the logs. If you want them to be collapsed and hidden use <span style=\"background:lightgrey; font-style:italic\">console.groupCollapsed()<\/span> instead.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/ytFKkjUxar11gDg8HG8d4cd21qgr4Pl0s5EKW9Z9vnxllm-X4_NDBwZv5ohw-Hgz9sURkR_PQE7yLHrCjrNv1OIubgO2yO5o-8papaT7jjcjaNIjy4_WexfqBMX6hkJmjvwQKQaP\" alt=\"console.group()\"\/><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"522\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-1-11-1024x522.jpg\" alt=\"\" class=\"wp-image-1817\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-1-11-1024x522.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-1-11-300x153.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-1-11-768x392.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-1-11-588x300.jpg 588w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-1-11.jpg 1318w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>3. Improve UX using console.time() &amp; console.timeEnd()<\/h2>\n\n\n\n<p>Getting things served to users quickly is amazing for UX. If you\u2019re trying to optimize your functions to return data quickly, you should use this amazing console hack instead of the typical setTimeout() functions. Use <span style=\"background:lightgrey; font-style:italic\">console.time()<\/span> to start the timer and use <span style=\"background:lightgrey; font-style:italic\">console.timeEnd()<\/span> to end the timer. The time between those two commands will automatically be output in milliseconds. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/_ePK8-cwTFqNhx_a4ovQ6Ge2HaJaBJnXnF4O28XucncvS8nb0YOPlEhPXHvURIgXy0hx-d_KLRPQdmr9tVWxFsG7bV6ExASVL0NCoKvIzMLp2JAuk0G4Uh3h0iqHUZTPrgKyz3rp\" alt=\"how to hack website timer\"\/><\/figure>\n\n\n\n<p>In some cases, you\u2019ll have a bunch of timers running together for multiple functions. To avoid confusion between which timer was started and ended, you can attach a label to the timers when you start them. Like this: <span style=\"background:lightgrey; font-style:italic\">console.time(\u2018function foo\u2019)<\/span>, and to end them use: <span style=\"background:lightgrey; font-style:italic\">console.timeEnd(\u2018function foo\u2019)<\/span>.<\/p>\n\n\n\n<p>If the function you\u2019re tracking has multiple stages and requires you to log time after completing each stage, you can use the following code:<\/p>\n\n\n\n<p>const start = Date.now();<br>\n\/\/ do some stuff<br>\nconsole.log(&#8216;Your function took &#8216; + (Date.now() &#8211; start) + &#8216; millis&#8217;);<\/p>\n\n\n\n<p>Output in the console:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/tXLKMZXZPk_b3fVmGo417LAEq90g3KEeGkSUEPYuVT3PCl_tV6btTMTsv6PEBhqf1q7NHlnY5iDMDeTOC4arUxn6pOiO_xY3qz45ZJY10ZCy7SMOC0vL7CpsC7fupugrp6UwcZhd\" alt=\"console.time() &amp; console.timeEnd()\"\/><\/figure>\n\n\n\n<p>In here, you can use the same console log command after completion of each stage.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"532\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-1024x532.jpg\" alt=\"\" class=\"wp-image-1818\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-1024x532.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-300x156.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-768x399.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-578x300.jpg 578w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group.jpg 1313w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>4. Debugging loops? Use console.count() &amp; console.countReset<\/h2>\n\n\n\n<p>When it comes to debugging loops, I catch myself just console logging the iterator to keep track of the other logs from the loop. In these scenarios, it\u2019s better to use <span style=\"background:lightgrey; font-style:italic\">console.count()<\/span> in the loop, then to console log the iterator. Here\u2019s what the results should look like:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/bBS1jDOeibjnfrNSfNztcmhlm48nHo4hbbwNBeZS-YC-wUKvrQwh1m4N4suTtd-FVlmoMbQYrd2hASOqm_FgkJDluR7u4oxDRADOyrKKvddXRzUZoHwXtj1-2WEfkpJbdOev8cLO\" alt=\"console.count() &amp; console.countReset\"\/><\/figure>\n\n\n\n<p>If you\u2019re tracking iterators in a nested loop, you can add a label like this: <span style=\"background:lightgrey; font-style:italic\">console.count(&#8216;Loop 1&#8217;)<\/span>. This will help you to identify them in the mess of all other loops.<\/p>\n\n\n\n<p>In order to reset the counter back to 0 just use <span style=\"background:lightgrey; font-style:italic\">console.countReset()<\/span> or <span style=\"background:lightgrey; font-style:italic\">console.countReset(&#8216;Loop 1&#8217;)<\/span><\/p>\n\n\n\n<p>TIP: Using <span style=\"background:lightgrey; font-style:italic\">console.count()<\/span> along with <span style=\"background:lightgrey; font-style:italic\">console.group()<\/span> will be a good combination while dealing with nested loops<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"458\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-574-1-1024x458.jpg\" alt=\"\" class=\"wp-image-1819\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-574-1-1024x458.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-574-1-300x134.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-574-1-768x344.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-574-1-670x300.jpg 670w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-574-1.jpg 1282w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>5. Getting lost? Use console.trace()<\/h2>\n\n\n\n<p>If you use libraries in your code, it is very likely that you have run into errors that involve fixing something in the library\u2019s code. Sometimes these libraries can be very complex and hard to understand. Using <span style=\"background:lightgrey; font-style:italic\">console.trace()<\/span> can be very helpful to identify the stack of a statement. It gives a clear picture of all the functions that were used along with its location.<\/p>\n\n\n\n<p>Example:<br> function a() {<br> &nbsp;&nbsp;&nbsp;&nbsp;function b() {<br>         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function c() {<br>             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.trace(&#8216;Where am I?&#8217;);<br>   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c();<br>     &nbsp;&nbsp;&nbsp;&nbsp;}<br>     &nbsp;&nbsp;&nbsp;&nbsp;b();<br> }<br> a(); <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/DbdJ2RxFLkiGZyZcp_IMbBghlJS66J1joZCDFKlpReL9V-39jO7AtgYE8_gscOuOKw7MPYGKG3yHD3f8t1ErCl7TdxetClIKd7c_WK9ajLgQtM8oZvuLlI33dq0lKQbwjBZ8Ga3S\" alt=\"console.trace()\"\/><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"522\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-575-1024x522.jpg\" alt=\"\" class=\"wp-image-1820\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-575-1024x522.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-575-300x153.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-575-768x391.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-575-589x300.jpg 589w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-575.jpg 1313w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>6. Keep logs private with console.debug(&#8216;Found Error 1&#8217;)<\/h2>\n\n\n\n<p>When your application is in the production phase, it\u2019s better not to show errors and your logs to the general public. But if you still want to track logs from your code and don\u2019t want the general public to see it, use <span style=\"background:lightgrey; font-style:italic\">console.debug(&#8216;Found Error 1&#8217;)<\/span>. Console debug allows you to hide all the logs in the console unless the \u2018Verbose\u2019 level of logs are enabled from the \u2018All levels\u2019 filter. This filter is turned off by default so that all the logs will be hidden until \u2018Verbose\u2019 is turned on. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/p3dfiBw84iv_tZ0_RVZi1X68qNT7ULBrHTaOvmscnFSxipzqY-2hfKfvbeJPfkCijuU9xFUwlR9aBpQ4xdtqXepMpj2X-wtEVT37SvYUY1foUuMA4SoPFMXhbxotQuzxitmpvEUX\" alt=\"console.debug('Found Error 1')\"\/><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"580\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-2-8-1024x580.jpg\" alt=\"\" class=\"wp-image-1821\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-2-8-1024x580.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-2-8-300x170.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-2-8-768x435.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-2-8-529x300.jpg 529w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-2-8.jpg 1313w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>7. Keep it neat with console.table()<\/h2>\n\n\n\n<p>In many cases, the log output of arrays or objects data is very ugly and hard to understand. With traditional <span style=\"background:lightgrey; font-style:italic\">console.log();<\/span> the results in the console looks like this:<br><br>Object<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/LIYEFnTxnGnGCKMjZp7GTG7BjHUfbTyIiXIPxQEXE8S2W7VmHB8IJqcMBJ3tHYTKKprBtLMaN7jDhHgJAPxuSAX621mjhofRpVEeFloPaU3LiNxDKnIJ63swGFEFGVBl5iVJmjeJ\" alt=\"console.table()\"\/><\/figure>\n\n\n\n<p>But if you use <span style=\"background:lightgrey; font-style:italic\">console.table()<\/span>, the console shows all the data in a very clear manner.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/LlUW3eo8s5bz1DNTXoESf3Bt8x_ZugQntQyZJo7qp7qmXe8azjuNcXPhAJGaqkdCgtl_jQOlVwR3tbMLVcVOsSDGNNhagXLBLeM20iFHnjEQm_gD-DeQpHtWPJZ3tRz2wdGoVMrf\" alt=\"console.table()\"\/><\/figure>\n\n\n\n<p>When logging Arrays as well, the results are more elegant and much easier to understand than direct console log.<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/yE6GDKIuUajxkpIjqaAeUliBuEVJkTyY9XLgehmf4zhQ9rLypMrJwfG7N0zdv-lqjl855VzzZAs4qwe9ipGqlqCgkf_AyKtaHp8xVy8m08Ej6QV9KDiY12Up8_dbycEAx0oNttKX\" alt=\"console.table()\"\/><\/figure>\n\n\n\n<p>In my opinion, using <span style=\"background:lightgrey; font-style:italic\">console.table()<\/span> for nested arrays is the best use case. Because if you compare the result with traditional console log your results are much easier to understand.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/Nh_mgYbgPD6mfMj-Ux9CNVXC0kW9YGQw6O3ljte60ZO-JLsMlS0D5MrZwNO40rAvwW8oVjk-KDUCUrI_ls8nHraRTESneSCTN35sbCWGx-EGb0-rNdFclQZuh8oxgPjtdCNRcjhR\" alt=\"console.table()\"\/><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"655\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/3323700-1-2-1024x655.jpg\" alt=\"\" class=\"wp-image-1822\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/3323700-1-2-1024x655.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/3323700-1-2-300x192.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/3323700-1-2-768x491.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/3323700-1-2-469x300.jpg 469w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/3323700-1-2.jpg 1244w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>8. Retrieve all interactive properties with console.dir()<\/h2>\n\n\n\n<p><span style=\"background:lightgrey; font-style:italic\">console.dir()<\/span> is another handy tool. It helps you retrieve all the interactive properties you can use on a JS object. It\u2019s most useful when you\u2019re trying to access properties of a DOM element. This tool can provide which exact property you will be using.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/rdfcO21H8wyEvdz2p5Cd4v76rTFeZaq7Jl-cgtAyxOfDUTlOEzzPmNCQxNY-RLfaKPRI6-TV_FdfIRg7pPWGbPGEP9IUzExDxvVE-FCrnQSNJcJq0CMYZxooeNq5DuOt5yY4WG4x\" alt=\"console.dir()\"\/><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"506\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-1-1024x506.jpg\" alt=\"\" class=\"wp-image-1823\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-1-1024x506.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-1-300x148.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-1-768x380.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-1-607x300.jpg 607w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Mask-Group-1.jpg 1313w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>9. Process if statements with console.assert()<\/h2>\n\n\n\n<p>In many cases, developers end up writing if statements only for console logging data. <span style=\"background:lightgrey; font-style:italic\">console.assert()<\/span> is a very great tool because it can process the if statement and will show an error in the console when the statement wasn\u2019t met. <\/p>\n\n\n\n<p>\n\nExample:<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/1Tddk7zG4VBalw2UFRNJwXKyMaAs9Sm1F8mbbGVdmp4E0TYO2eMaB7UeK-OrEH_xtbhj98pXDinrh6UN_ephDHsHWJXVQ6tIknLb3sm-i479nuJRrXbMHLX5G1x1DIC90XEhioMC\" alt=\"console.assert()\"\/><\/figure>\n\n\n\n<p><span style=\"background:lightgrey; font-style:italic\">console.assert()<\/span> takes 2 parameters, (if statment, {label: \u2018info\u2019, label: \u2018info\u2019 \u2026..})<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"316\" src=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-3-5-1024x316.jpg\" alt=\"\" class=\"wp-image-1824\" srcset=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-3-5-1024x316.jpg 1024w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-3-5-300x93.jpg 300w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-3-5-768x237.jpg 768w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-3-5-973x300.jpg 973w, https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-3-5.jpg 1245w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>10. Add CSS styling to your console with %c<\/h2>\n\n\n\n<p>If you want your console to look fancy, it\u2019s possible to add CSS styling to it. To add the styling, use the traditional <span style=\"background:lightgrey; font-style:italic\">console.log()<\/span> but in the text add <span style=\"background:lightgrey; font-style:italic\">%c<\/span> before the characters you want to style. In the second parameter add the CSS you want to apply to the text.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/Vcwsp3XMItpeOOgFX2FPYYAU0reUoi2o0xx5fxnlDDo5WapKbZ5sW0YOQlHeFtMSyTazE3N4smAckwM2p6x4aSLboPItXcCC7uMMTlstZvDaXWZlZ66D9exDdMnrB-auG19EcnhR\" alt=\"CSS styling to your web console with %c\"\/><\/figure>\n\n\n\n<p>You can also apply different styles on different parts of text like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/iwnTl1KUeNbNckFtl8IhxU9CSKj01PTrVEFdpYHJ8AF0KKNG_WSMgT9XWMGAFzVxBSaIO6Ud-WZH1w3p7hmY1L-6IE1FrvJHDcc3_wpj7aYzimoNk7G0wkuuapj-0lTtvqHMDmTe\" alt=\"CSS styling to your console with %c\"\/><\/figure>\n\n\n\n<p>This method is also used by companies like Facebook to give their users warnings like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/9h0x_pByaRqxIJddbnrqZnw4i6vxh7pxvb52I8cgvKj_QDTtPcyM0cFT-06hXHLnM3Haft6osWHRZMDrlOG4OSlovEVAX2htvVY8aqoVx1Tt6iD_Goao65YE9oX9zQfjuw1ZBwmS\" alt=\"\"\/><\/figure>\n\n\n\n<p>This is just one of the many ways you could use this hack<\/p>\n\n\n\n<p>So there you have it! 10 Console hacks to hopefully make your life easier as you work through browsers. Did any of these make your life easier, or maybe you\u2019ve got a tip we didn\u2019t include. Let us know!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Productivity in the workplace is always a major concern. We try all kinds of things to boost our productivity from [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>10 Browser Console Hacks - Regex SEO Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.regexseo.com\/blog\/10-browser-console-hacks\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"10 Browser Console Hacks - Regex SEO Blog\" \/>\n<meta property=\"og:description\" content=\"Productivity in the workplace is always a major concern. We try all kinds of things to boost our productivity from [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.regexseo.com\/blog\/10-browser-console-hacks\/\" \/>\n<meta property=\"og:site_name\" content=\"Regex SEO Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-06-21T23:23:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-07T16:32:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-571-2-1024x706.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\">\n\t<meta name=\"twitter:data1\" content=\"Shubh Sheth\">\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data2\" content=\"5 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.regexseo.com\/blog\/#website\",\"url\":\"https:\/\/www.regexseo.com\/blog\/\",\"name\":\"Regex SEO Blog\",\"description\":\"Your SEO, SEM and SMM Information Source\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.regexseo.com\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.regexseo.com\/blog\/10-browser-console-hacks\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2020\/09\/Group-571-2.jpg\",\"width\":1267,\"height\":873},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.regexseo.com\/blog\/10-browser-console-hacks\/#webpage\",\"url\":\"https:\/\/www.regexseo.com\/blog\/10-browser-console-hacks\/\",\"name\":\"10 Browser Console Hacks - Regex SEO Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.regexseo.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.regexseo.com\/blog\/10-browser-console-hacks\/#primaryimage\"},\"datePublished\":\"2019-06-21T23:23:29+00:00\",\"dateModified\":\"2023-02-07T16:32:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.regexseo.com\/blog\/#\/schema\/person\/8f0c3e071fde34cc78700c9856d6d598\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.regexseo.com\/blog\/10-browser-console-hacks\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.regexseo.com\/blog\/#\/schema\/person\/8f0c3e071fde34cc78700c9856d6d598\",\"name\":\"Shubh Sheth\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.regexseo.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.regexseo.com\/blog\/wp-content\/uploads\/2019\/06\/IMG-20181221-WA0001-e1561156485625-150x150.jpg\",\"caption\":\"Shubh Sheth\"},\"sameAs\":[\"https:\/\/www.regexseo.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/posts\/307"}],"collection":[{"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":49,"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":3392,"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions\/3392"}],"wp:attachment":[{"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.regexseo.com\/blog\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}