The difference between alert () and Console.log () in JavaScript

Source: Internet
Author: User

We do JS debugging When using alert can display information, debugging programs, alert pop-up window will interrupt the program, if you want to display information in the loop, hand click Close Window is exhausted. And the alert display object is always displayed as [object]. I write the log although you can display some object information, but a lot of feature support is not console good

[1]alert ()

[1.1] Blocking action, no click OK, subsequent code can not continue to execute

[1.2]alert () can only output a string if the alert output is an object that automatically calls the ToString () method

e.g. alert ([+/-]);

[1.3]alert does not support the notation of multiple parameters, only the first value can be output

e.g. alert (//1);

[2]console.log ()

[2.1] output in Print station

[2.2] can print any type of data

e.g. Console.log ([+ +]);//[1,2,3]

[2.3] Support for the formulation of multiple parameters

e.g. Console.log (1 2 3)//

are alert and console.log different results?

Score = [1,2,3];sortedscore = [];console.log (score); Sortedscore = Score.sort (sortnumber) Console.log (Sortedscore); function Sortnumber (A, b) {  return b-a;}

  

Above output:
[3, 2, 1]
[3, 2, 1]

But change to alert:

Web Design

Score = [1,2,3];sortedscore = [];alert (score); Sortedscore = Score.sort (sortnumber) alert (sortedscore); function Sortnumber (A, b) {  return b-a;}

  


Above output:
1, 2, 3
3, 2, 1

Why is that? It should not all be:
1, 2, 3
3, 2, 1
It?

After some research found that chrome implementation of the problem, the output is not properly optimized, the actual execution of the Console.log deferred, equivalent to "lazy" evaluation, encountered in the array, object, such as the reference type of the above problem.

The difference between alert () and Console.log () 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.