console.log是异步么?

让我们来看一个例子:

1 var a = {};
2 console.log(a);
3 a.foo = ‘foo‘;
4 console.log(a);

但是问题来了:在chorme跟firfox一样么?

结果是在chrome中显示  {foo: ‘foo‘},{foo: ‘foo‘}

而在firefox中是 {},{foo: ‘foo‘};

显然:在chrome中是异步的,而在firfox中是同步的;

时间: 2024-08-15 22:03:29

console.log是异步么?的相关文章

Chrome 中的console.log 之异步或者同步

以下结果只是我在chrome里面做的实验 图1 从图1可以看出  先执行console.log 打印出b 后才执行b.b=2; 然而事实是这样的吗? 图2 是否觉得跟图1得出的结论相悖论? 从结果推测执行顺序是 console.log a.a.a1.a2.a3=3; 后才打印a

js的线程和同步异步以及console.log机制

项目上线了,闲下来就写写东西吧.积累了好多东西都没有做笔记~挑几个印象深刻的记录一下吧. js的同步异步以及单线程问题: 都知道单线程是js的一大特性.但是通常io(ajax获取服务器数据).用户/浏览器自执行事件(onclick.onload.onkeyup等等)以及定时器(setTimeout.setInterval)这些异步操作又是怎样工作的呢. 我们把js的任务分为两种:同步任务,异步任务: 举个例子吧:   let a=1; console.log("同步任务"): setT

使用console.log打印的内容不一定可信

在工作中遇到,使用console.log()输出对象信息时,出现输出的信息跟自己想的不一样的问题,导致调试bug时,思路走偏. 当时参考了别人的issues已经讲的很清楚了. 这里自己再记录一下 问题描述: 即使我直接在赋值语句const obj = {age: 20}后面紧跟console.log(obj), 在浏览器的控制台,看到的也不一定的age字段,也不一定是20. 因为,如果在后面的代码中,修改了age字段的值,那控制太看到的就不是20了. 比如执行如下代码: let obj = {a

【转】console.log 用法

转自http://www.cnblogs.com/ctriphire/p/4116207.html 大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能大家对console.log会有一定的了解,心里难免会想调试的时候用alert不就行了,干嘛还要用console.log这么一长串的字符串来替代alert输出信息呢,下面我就介绍一些调试的入门技巧,让你爱上co

JavaScript原型链中toString()方法输出alert()和console.log()得到不同的结果

<script language="javascript"> function myObj(){ var total = 0; } myObj.prototype.add = function(a,b){ this.total = a + b; } myObj.prototype.toString = function(){ return this.total; } var obj = new myObj(); obj.add(1,2); console.log(obj);

美化console.log的文本(转载)

原文地址:http://www.css88.com/archives/5260 console.log("%c css88.com", "font-size:20pt") console.log("%c 前端开发 %c css88.com %c 愚人码头", "color:red","","color:orange;font-weight:bold") console.log("

[Javascript] Format console.log with CSS and String Template Tags

The Chrome console allows you to format messages using CSS properties. This lesson walks you through the syntax of formatting your logs with css then refactoring into a template tag function to make formatting more reusable. const debug = (label, sty

console.log(+‘2’) console.log(-‘2’) 输出什么?

+‘2’ 会将字符串‘2’转换为number类型2 -‘2’会将字符串‘2’转换为number类型1(自减); 所以 数字字符串之前存在数字中的正负号(+/-)时,会被转换成数字 console.log(typeof '3'); // string console.log(typeof +'3'); //number 同样,可以在数字前添加 '',将数字转为字符串 console.log(typeof 3); // number console.log(typeof (''+3)); //str

console.dir() 与 console.log() 区别

Difference console.log prints the element in an HTML-like tree console.dir prints the element in a JSON-like tree Example Specifically, console.log gives special treatment to DOM elements, whereas console.dir does not. This is often useful when tryin