console window

console window in javascript

console window is very useful for interacting with and debugging your code.

You can open the console window by pressing ctrl + shift + j in chrome and ctrl + shift + k in firefox.

In console window you can type your javascript code.

Chrome Console Window (ctrl+shift+j)
Chrome Console Window (ctrl+shift+j)
Firefox Console Window (ctrl+shift+k)
Firefox Console Window (ctrl+shift+k)

console window to check javascript statement

In the console window you can enter any javascript code and methods and test it locally.

Following are the commonly used javascript Methods.

These methods output can be viewed only in console window. So open the console window to see the following codes output.

  • console.assert()

    It is used to write an error message if the assertion is false.

    Example

    Try Yourself
  • console.clear()

    It is used to clear all the contents in the console window and replace it with a simple message "Console was cleared".

    This method has no effect in Google Chrome, if the "Preserve log upon navigation" setting is selected in it.

    Example

    Try Yourself
  • console.count()

    It is used to count the total number of times it is called.

    This method can have an single argument.

    If an argument is given to it, it check the number of times the value in the argument is called.

    If an argument is not given, it counts the total number of times the count method is called.

    Example

    Try Yourself
  • console.dir()

    It is used to display all the properties of a specific Javascript object.

    It displays the properties in list.

    Example

    Try Yourself
  • console.dirxml()

    It is used to display all the properties of a specific HTML/XML element.

    It displays the properties in list.

  • console.error()

    It is used to display an error message in the console window.

    Example

    Try Yourself
  • console.group()

    It is used to create a group like structure by intenting the contents which are following this method.

    The intent level increases by one whenever this method is used.

    It can be used to create a nested group like structure.

    Example

    Try Yourself
  • console.groupCollapsed()

    This method is used to create a group in a tree model.

    It is similar to console.group(), but the only difference is console.groupCollapsed() is used to create the group in dropdownlist.

    Example

    Try Yourself
  • console.groupEnd()

    This method is used to break the intentation created, and shifts the contents to left side.

    Example

    Try Yourself
  • console.info()

    It is used to print an informal message in the console.

    Example

    Try Yourself
  • console.log()

    It is used to print an simple text message in the console.

    Example

    Try Yourself
  • console.table()

    It is used to create a table using the given values.

    It has argument which must contains datas, it can be in array or object.

    Example

    Try Yourself
  • console.time()

    It is used to start a timer.

    A name must be given for each timer.

    It is used to calculate the time taken to do an operation.

    This method must be used along with the console.timeEnd() method, to get the total time.

    Example

    Try Yourself
  • console.timeEnd()

    It is used to stop a timer which is already started using that timers name.

    It is used to calculate the time taken to do an operation.

    This method must be used along with the console.time() method, to get the total time.

    Example

    Try Yourself
  • console.trace()

    It is used to display a stack trace.

    It will show the call path that goes through each path to reach a point.

    Example

    Try Yourself
  • console.warn()

    It is used to display a warning message.

    Warning messages will be displayed with yellow background.

    Example

    Try Yourself