小编yoh*_*ver的帖子

为什么我的空对象文字记录为false?

我不太明白为什么if声明评估trueconsole.log比较没有.

我仔细检查了MDN文档,他们说这{}是一个真正的价值.那么为什么我的console.log陈述不同意?

作为最后一个沟,我确实尝试过使用==而不是===.

var test = {};
    
console.log(test);          
console.log(test === true); 
console.log({} === true);   
    
if ({}) {
    console.log('What the ?');
} 
Run Code Online (Sandbox Code Playgroud)

javascript

6
推荐指数
1
解决办法
244
查看次数

为什么我的forEach循环不编辑数组?

在课堂上,我以他们为例,介绍了使用forEach()循环编辑数组内容的方法。

类示例:

var donuts = ["jelly donut", "chocolate donut", "glazed donut"];

donuts.forEach(function(donut) {
  donut += " hole";
  donut = donut.toUpperCase();
  console.log(donut);
});

Prints:
JELLY DONUT HOLE
CHOCOLATE DONUT HOLE
GLAZED DONUT HOLE
Run Code Online (Sandbox Code Playgroud)

问题是,当我尝试使用相同的技术解决测验问题时,它不会更改数组的值。我认为这与if声明有关,但他们要求我们使用该声明,所以为什么不告诉我们存在问题?

我的代码:

/*
 * Programming Quiz: Another Type of Loop (6-8)
 *
 * Use the existing `test` variable and write a `forEach` loop
 * that adds 100 to each number that is divisible by 3.
 *
 * Things to note:
 *  - you must …
Run Code Online (Sandbox Code Playgroud)

javascript arrays

2
推荐指数
2
解决办法
2441
查看次数

标签 统计

javascript ×2

arrays ×1