Beyond console.log()

Subscribe to my newsletter and never miss my upcoming articles

We all have been using console.log(), but many more options are available out there.Let us see them now

The most useful type beyond log is console.table()


  • Takes in JSON or an array and prints in table format
  • Very handy while visualising json objects and arrays
  • Syntax:


Alt Text

                        id: "1",
                        key: "value",
                        count: 2,
                         id: "2",
                         key: "value2",
                             count: 22,
                            id: "3",
                            key: "value3",
                                count: 5,

Alt Text

The next useful method is error


  • useful to differentiate errors from output logs while debugging

Alt Text

  • red in color

Next one, useful while calculating runnning times is time method


  • To understand this, let us assume scenario of a stopwatch Alt Text
  • console.time()
    • equivalent to stopwatch start
  • console.timeLog()
    • like stopwatch lap/split
  • console.timeEnd()

    • stopwatch end

    • It works on basis of label. Label should be the same to get expected output

                  // "ForLoop" is label here
          for (let i = 0; i < 5; i++) {

    Alt Text

Next one is warning


Alt Text

 - yellow color 
 - For warnings



  • evaluate assertion statement and if it is false displays the message
    console.error({ msg1: "msg1", msg2: "msg2" });
            -----------same as---------
console.assert(3 === 2, { msg1: "msg1", msg2: "msg2" });

Alt Text

Other way console.assert(assert_statement,message,args)

console.assert(false, "%d nd type for  %s ",2,"console.assert() method");

Alt Text

Useful method for counting

  • console.count() works on basis of label

    • console.count(label)

           for (let i = 0; i < 3; i++) {
           // output for
           console.count()  console.count("label")   console.count(i)
           default: 1                label: 1                0: 1
           default: 2                label: 2                1: 1
           default: 3                label: 3                2: 1
      • console.count()
        • if no label is mentioned it will consider default as label
        • The problem with default is it will continue the count like this Alt Text
    • console.countReset(label)

    • resets count of specified label to 0

I mentioned only few methods which I think are more helpful.To check all the available methods refer here

No Comments Yet