1.alert pops up in the page
Console.log is displayed on the console
Example
1 var aa= "Silence"; 2 alert (typeof (AA)); 3 Console.log (typeof (AA));
Alert display
Console.log in console display
The 2.alert () function blocks the execution of the JavaScript program, causing side effects, while Console.log () prints the information only in the console and therefore does not cause similar concerns
3. The toString () method output alert () and Console.log () in the JavaScript prototype chain have different results
1 var aa=[1,2,3]; 2 array.prototype.tostring=function () {3 return "I love U"; 4 }5 alert (AA); 6 Console.log (AA);
Console.log () can print any type of data. Alert () can only output a string if the alert output is an object that automatically calls the ToString () method. If you want the Console.log () output to be the same as alert, you need to call ToString ():
Console.log (aa.tostring ()); The output in this console is " I Love U ";
Alert and Console.log