Console. log ();
When you use console. when using the log () function, the following firebug must be enabled. Otherwise, this function is invalid when running in firefox and affects normal programs. If you use IE to open the function, an error will occur.
The first parameter 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, integer
% I (number type not supported currently)
% F floating point type (currently not supported)
% O link object
Console. log () Usage Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> javascript console. log () usage </title>
<Script type = "text/javascript">
/*
Console. log was originally a "patent" of Firefox, and strictly said it was a "trick" for debugging unique to Firefox after Firebugs was installed ".
This trick is learned by IE8, but it is more difficult to use than Firebugs. The console. log can output the result only when the debugging window (F12) is enabled. Otherwise, an error is reported.
Today, we can see that Opera also has something called dragonfly. You can use this to view DOM, which is comparable to Firebug. However, you still cannot use console. log. So someone provides the following code:
Window. console = window. console || {};
Console. log | (console. log = opera. postError );
After testing, the above Code can be used.
Now, Firefox, IE, and Opera can all use console. log.
Of course, the console. log in IE and Opera is much simpler than the original console. log in Firebugs. For example, if the parameter is an Object or an array, no further display function is available.
*/
// Variable
Var I = 'I am a string ';
Console. log ('variable: ', I );
// Array
Var arr = [1, 2, 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 ('object: ', obj1 );
// Object Array
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
Array: [1, 2, 3, 4, 5]
Object: 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>
</Head>
<Body>
</Body>
</Html>