我以为我掌握了提升的概念,但下面的代码让我感到困惑。怎么返回1呢?第二个 example() 函数会被提升到第一个函数之上吗?
function example() {
return 9;
}
console.log(example());
function example() {
return 1;
}Run Code Online (Sandbox Code Playgroud)
如果在编译阶段提升函数声明并在执行阶段执行函数表达式。下面的代码为什么返回7?这仅仅是因为首先声明了示例表达式吗?
var example = function() {
return 7;
}
console.log(example());
function example() {
return 0;
}Run Code Online (Sandbox Code Playgroud)
先感谢您!
const string = "Hello There";
const chars ={};
for(let character of string){
if(!chars[character]){
chars[character] = 1;
}else{
chars[character]++;
}
}
console.log(chars);
Run Code Online (Sandbox Code Playgroud)
以下代码将打印出现在字符串中的唯一字母的数量。我知道感叹号的意思是“假”,但我不明白它在下面的例子中代表什么:
!chars[character]
Run Code Online (Sandbox Code Playgroud)
我很难理解如何将它的字符与其他字符进行比较,因为它清楚地说明了 char[at a current i]。如果有人可以举一个更简单的例子。我尝试调试它,但也无法理解。