It is mainly for your convenience to use JavaScript. You can see what you output on the page.
Compared to alert, his advantages are:
1. It can see the structure word. If it is an alert, an object is [object object], but the console can see the content of the object.
2. Console will not interrupt your page operation. If the content pops up with alert, the page will die, but your page can still operate normally after the console outputs the content.
3.The content in onsole is very rich. You can enter: console in the console and then you can see:
Console {memory: MemoryInfo, debug: function, error: function, info: function, log: function…}The simple code is as follows:
<!DOCTYPE html><html><head><title></title><meta charset="utf-8"><script type="text/javascript">var a=3;var b='What is this';var $c='Ah! ';console.log(a,b,$c);var $='jqery';alert($);</script></head><body></body></html>
A window will pop up in the browser with the words jquery displayed.
Specific usage of console.log in javascript
//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('Object:',obj1);//Object array var objArr1 = [obj1,obj2,obj3];var objArr2 = [[obj1],[obj2],[obj3]];console.log('Object array1:',objArr1);console.log('Object array1:',objArr2);/*Output: Variable: I am a string array: [1, 2, 3, 4, 5]Object: Object { key1="value1", key2="value2", key3="value3"}Object array1: [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"}]]*/The above is the console.log and pop-up alert in javascript introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!