Usage of console in JavaScript

Source: Internet
Author: User
Tags object object

JavaScript's Console.log () usage//variables
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 array 1: ', OBJARR1);
Console.log (' Object array 1: ', OBJARR2);


/*
Output:
Variable: I am a string
Array: [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"}]]
*/
    1. Xmbuxi

      [Email protected]

      Reference address

      The usefulness of Console.log ()

      It's mostly handy for your modal JavaScript, and you can see what you're outputting in the page.

      His advantages compared to alert are:

      He can see the structure of things, if it is alert, fade out an object is [Object Object], but the console can see the contents of the object.

      Console does not interrupt the operation of your page, if you use alert to bounce out the content, then the page is dead, but the console output after your page can be normal operation.

      The console is very informative and you can enter console in the console and you will see:

Usage of console in JavaScript

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.