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

Source: Internet
Author: User

[1]alert ()

[1.1] Blocking action, no click OK, subsequent code cannot continue execution

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

e.g. alert ([1,2,3]);//' 1,2,3 '

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

e.g. alert (1,2,3);//1

[2]console.log ()

[2.1] On the print table output

[2.2] can print any type of data

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

[2.3] To support multiple parameters of the wording

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

Are the results of alert and console.log different?

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:

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? Should not all be:
1, 2, 3
3, 2, 1
Do you?

After a study found that the problem is the implementation of chrome, the output did not fit the optimization, the actual execution of the Console.log deferred, the equivalent of "lazy" evaluation, the array, objects such as the reference type on the above problem.

https://bugs.webkit.org/show_bug.cgi?id=35801

This is a very historical BUG that has been fixed in the development version last month.

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.