1、在你的计算机上安装 Node,然后运行命令 node –version 和 npm –version 来查看你安装的版本。
请从以下链接下载并安装最新的长期支持(LTS)版本的 Node 和 NPM:
安装完成后,在命令行中运行以下命令以查看版本信息:
node --version
npm --version
2、typeof 是什么类型的东西?它是表达式、函数还是其他的?
typeof 是一个运算符,不是函数。应用它时,在空格后输入要检查类型的对象名称,例如 typeof dress ,而非 typeof(dress) 。
3、+= 有什么作用?
+= 是一种复合赋值运算符,例如 current += 1 等价于 current = current + 1 ,用于将变量 current 的值增加 1。
4、编写一个名为 isTruthy 的函数,对于 JavaScript 认为为真的值返回 true,对于 JavaScript 认为为假的值返回 false,但空数组除外,对于空数组,isTruthy 应返回 false。
以下是实现该功能的 JavaScript 代码:
function isTruthy(value) {
return value || (Array.isArray(value) && value.length > 0);
}
5、NaN代表什么?你期望下面代码的输出是什么?运行代码,看看结果是否符合你的预期。在处理现实世界数据时,这种行为有什么影响?代码如下:const first = [3, 7, 8, 9, 1]; console.log( aggregating ${first} ); let total = 0; for (let d of first) { total += d; } console.log(total); const second = [0, 3, -1, NaN, 8]; console.log( aggregating ${second} ); total = 0; for (let d of second) { total += d; } console.log(total);
-
NaN代表非数字(not a number)。 - 对于第一段代码,期望输出是数组元素之和
3 + 7 + 8 + 9 + 1 = 28。 - 对于第二段代码,由于
NaN参与运算结果仍为NaN,所以期望输出是NaN。 - 在处理现实世界数据时,
NaN的存在可能导致计算结果错误或无法得到有效结果,需要对数据进行预处理以检测和处理NaN值。
6、解释创建常量creature的赋值语句中发生了什么。代码为:const genus = ‘Callithrix’; const species = ‘Jacchus’; const creature = {genus, species}; console.log(creature); 输出为 { genus: ‘Callithrix’, species: ‘Jacchus’ }
首先定义了两个常量 genus 和 species ,分别赋值为 'Callithrix' 和 'Jacchus' 。
然后使用对象字面量语法创建了一个常量 creature ,这里使用了 ES6 的简洁语法,对象的属性名与之前定义的常量名相同,属性值即为对应常量的值。
最后打印出 creature 对象,显示其包含:
-
genus属性值为'Callithrix' -
species属性值为'Jacchus'
7、下面两个程序有什么区别?第一个程序:const creature = { genus: ‘Callithrix’, species: ‘Jacchus’ }; const {genus, species} = creature; console.log( genus is ${genus} ); console.log( species is ${species} ); 第二个程序:const creature = { first: ‘Callithrix’, second: ‘Jacchus’ }; const {genus, species} = creature; console.log( genus is ${genus} ); console.log( species is ${species} );
第一个程序中,对象 creature 的属性名与解构赋值时指定的变量名( genus

最低0.47元/天 解锁文章
2135

被折叠的 条评论
为什么被折叠?



