Using JS Console object, in the console printing mode information Test JS implementation _javascript Skills

Source: Internet
Author: User
Tags assert

A chance, open Baidu when pressed the F12, and then see the console inside the output of Baidu recruitment ads, feeling pretty handsome, and then have this blog.

Since you can do this in the console output information, then debug JS after the time can not save a lot of trouble! Avoid fraught, intentionally using the for (var i in console) to view the console support for the various browser consoles,

The results are as follows:

IE 11 Console

Log, info, warn, error, Debug, Assert, Time, Timeend, group, groupcollapsed, GroupEnd, Trace, clear, dir, di Rxml, Count, Countreset, CD, select, Profile, Profileend

Firebug Console

Log, debug, info, Warn, exception, Assert, dir, Dirxml, Trace, group, groupcollapsed, GroupEnd, profile, Prof Ileend, Count, clear, Time, timeend, timeStamp, table, error

Chrome Console

Memory, _COMMANDLINEAPI, debug, error, info, log, warn, dir, dirxml, table, Trace, Assert, Count, Marktimelin E, profiles, Profileend, time, Timeend, TimeStamp, Timeline, timelineend, group, groupcollapsed, GroupEnd, clear

You can see that I tested the browser on the log, info, warn, error, debug five basic methods are supported, note that I use IE 11, the other version I did not test, and Firefox itself is not with the console, the need to load Firebug plug-ins and And start it, can console, otherwise is JS error. In order to use more convenient, you can encapsulate it, to determine the browser support for the console, do not support the use of the original alert or other methods.

Simple usage:

Console.log ("Log Information");
Console.info ("General Information");
Console.debug ("Debugging Information");
Console.warn ("warning hint");
Console.error ("error hint");

Format output:

Console.log ("%d years%d months%d days", 2014, 5, 20);//date format output
Console.log ('%c has color output information ', ' Color:white; Background-color: #0055CC ');//Format output


Output variables:

var who= ' you ';
Console.log (' Output variable We support ', you)/Read variable


Output array:

var arr = [1, 2, 3, 4, 5];
Console.log (' array: ', arr);//output array

The above use of JS console object, in the console printing mode information Test JS implementation is small set to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.