JavaScript uses Console.log method to _javascript techniques in Firebug debugging

Source: Internet
Author: User
Console.log ();

When you use the Console.log () function, the following firebug must be opened, otherwise this function in the Firefox runtime is not valid and affect the normal program, if you open with IE, will be wrong.


The first argument can be a string that contains the formatted placeholder output, for example:

Console.log ("The%s jumped over%d tall buildings", animal, count);

format string type
%s string
%d, integral type
%i (no support for digital type)
%f floating-point type (no support for digital type)
%o Linked objects

console.log () usage
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
Console.log () Usage of <title>javascript </title>
<script type= "Text/javascript" >
/*
Console.log originally is Firefox "patent", strictly speaking is installed after the firebugs of Firefox unique debugging "trick".
This recruit, IE8 learned, but with more than firebugs trouble, only in the Open Debugging window (F12), console.log can produce results, or the error.
See Opera today also has a call Dragonfly Dongdong, use this thing to view DOM, already can compare with Firebug, however still can't use Console.log. So someone has provided this two-sentence code:
Window.console = Window.console | | {};
Console.log | | (Console.log = Opera.posterror);
After testing, the above code works.
At this point, Firefox/ie/opera can use the Console.log.
Of course, IE and Opera under the Console.log than firebugs original Console.log, or too simple, such as parameter is Object or array has no further display function.
*/
Variable
var i = ' I am a string ';
Console.log (' variable: ', i);
Array
var arr = [1,2,3,4,5];
Console.log (' array: ', arr);
Object
var obj1 = {
Key1: ' value1 ',
Key2: ' value2 ',
Key3: ' Value3 '
};
var obj2 = {
Key6: ' Value4 ',
Key5: ' Value5 ',
Key4: ' Value6 '
};
var obj3 = {
Key9: ' Value7 ',
Key8: ' Value8 ',
Key7: ' Value9 '
};
Console.log (' objects: ', obj1);
Array of objects
var objArr1 = [Obj1,obj2,obj3];
var objArr2 = [[Obj1],[obj2],[obj3]];
Console.log (' Object array 1: ', OBJARR1);
Console.log (' Object array 1: ', OBJARR2);
/*
Output:
Variable: I am a string
Arrays: [1, 2, 3, 4, 5]
Objects: Object {key1= "value1", key2= "value2", key3= "Value3"}
Object array 1:[object {key1= "value1", key2= "value2", key3= "Value3"}, Object {key6= "Value4", key5= "Value5", key4= "Value6"}, Object {key9= "Value7", key8= "Value8", key7= "Value9"}]
Object array 1:[[object {key1= "value1", key2= "value2", key3= "Value3"}], [object {key6= ' value4 ', key5= ' value5 ', key4= ' Value6 '}] , [Object {key9= "Value7", key8= "Value8", key7= "Value9"}]]
*/
</script>
<body>
</body>
Related Article

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.