When debugging js, we can use alert to display information and Debug programs. The alert pop-up window will interrupt the program. If you want to display information in a loop, you will be exhausted by clicking close window. In addition, the alert Display object is always displayed as [object]. Although the self-written log can display some object information, many functions do not support the console.
[1] alert ()
[1.1] blocking effect. If you do not click OK, subsequent Code cannot be executed.
[1.2] alert () can only output strings. If alert outputs an object, the toString () method is automatically called.
E.g. alert ([1, 2, 3]); // '1, 2, 3'
[1.3] alert does not support writing multiple parameters. Only the first value can be output.
E.g. alert (1, 2, 3); // 1
[2] console. log ()
[2.1] output on the printer
[2.2] printing any type of data
E.g. console. log ([1, 2, 3]); // [1, 2, 3]
[2.3] Support for writing multiple parameters
E.g. console. log (1, 2, 3) // 1 2 3
What are the results of alert and console. log?
score = [1,2,3];sortedScore = [];console.log(score);sortedScore = score.sort(sortNumber)console.log(sortedScore);function sortNumber(a, b) { return b - a;}
The above output:
[3, 2, 1]
[3, 2, 1]
But changed to alert:
score = [1,2,3];sortedScore = [];alert(score);sortedScore = score.sort(sortNumber)alert(sortedScore);function sortNumber(a, b) { return b - a;}
The above output:
1, 2, 3
3, 2, 1
Why? Not all:
1, 2, 3
3, 2, 1
?
After some research, it is found that the problem of chrome implementation is that the output is not properly optimized, and the console is used. the actual execution of log is postponed, which is equivalent to the value of "inertia". In case of reference types such as arrays and objects, the above problem occurs.
Https://bugs.webkit.org/show_bug.cgi? Id = 35801
This is a very historical BUG. It was fixed in the development version last month.