gpt4 book ai didi

javascript - 现代(2018)浏览器不支持 forEach 吗?

转载 作者:行者123 更新时间:2023-11-30 20:31:17 24 4
gpt4 key购买 nike

今天我参加了网络技术考试。其中一个问题是

Which loops exist in JavaScript?

可能的答案是:

  1. while, do-while, for, foreach
  2. while, do-while, for
  3. while,do-while, for-next
  4. while, do-while, for, foreach, repeat-until
  5. while, for, foreach, for-next

我选择了答案1。

这似乎是错误的。我收到的对我的回答的评论是:

WHILE, DO-WHILE and FOR are the most used standardised loops in javascript. Modern browsers implement ECMAScript4, and these do not support any other loops. Note: ECMAScript5 supports newly FOREACH, but this is still not implemented in the modern browsers.

The correct answer is: while, do-while, for

我的问题是:这个评论是不是有点过时了?或者是 w3schools's statement关于完全支持 ECMAScript5 的错误?

最佳答案

可能的答案列表不完整。它不包括 for...in (ES1) 和 for...of (ES6) 语句。

其次,我相信 foreach 没有引用 Array.forEach 方法。所有选项均引用来自不同语言的循环结构...来自 VB/VBScript/VB.Net 的 for-next,来自 Pascal 的 repeat-untilforeach 来自 PHP。因此,如果他们的意思是 JavaScript 中存在哪些循环字面上,那么:

  1. 您选择的答案是错误的。
  2. 选项#2 正确没有错。但是它缺少 for...infor...of

最后,给你的解释是不正确的:

Modern browsers implement ECMAScript4, and these do not support any other loops.

以上两种说法都是错误的,因为 (i) 没有 ECMAScript4 这样的东西 (ii) for...in 循环总是存在的。没有必要进一步剖析其余的解释。

关于javascript - 现代(2018)浏览器不支持 forEach 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50310521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com