我看到javascript有点奇怪的行为。我是这种语言的新手,但从我所看到的,如果你从console.log()方法中增加一个变量(或以任何方式改变它),这实际上是全局改变变量。
a,b = np.ones(2)
np.add(a,b,where = False) #returns 6.0775647498958414e-316
a,b = 1,1
np.add(a,b, where = False) #returns 12301129,
#running this line several times doesn't give the same result every time...
这是javascript特有的东西吗?我原以为变量不会受到全局影响,最后一个print语句会显示为0。
答案 0 :(得分:1)
使用++会影响变量,如果你只想用于日志目的,你必须使用+1,这是它在javascript中的工作原理^^
var a = 0;
console.log(a); //prints 0
console.log(a+1);
console.log(a+1);
console.log(a+1);
console.log(a); //prints 0