× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Get to know the console object

Jan 02, 2017
<p><code>console.log("special message");</code> is often the first object/method that people use when writing JavaScript for the browser. I used it for years without understanding what exactly I was doing, but <code>console</code> is an object and <code>log()</code> is a method of that object. First tip is that <code>log()</code> is a function that can take any number of arguments. <code>console.log('Current count: ', currentCount, ' Starting count: ', startingCount);</code> <em>Assuming you have some variables like <strong>currentCount</strong> in your program</em>, this could be an example of a log with labels. There are a bunch of other great methods on the console object. Second tip is that I only recently noticed the <code>clear()</code> method. I now often put <code>console.clear()</code> at the beginning of a js program or function so that my console doesn't pile up with outdated logs <em>which can lead to confusion</em>. Try it out and look up all the other useful methods here.</p>
comments powered by Disqus