哪个给定的 for 循环更快?

which of the given for loop is faster?

嗯,我今天去面试了,面试官问了我一个问题,是这样的。

    let a = "Aditya";
    1.for (let i=0; i<a.length; i++)
    2.for(let i=a.length; i>0; i--)
    3.for(let i=0, length=a.length; i<length; i++)

以上哪个for循环运行得更快1、2、3? 安排一下,并说明理由。 我觉得我用 (1) 最多,所以它可能更快,但他告诉我我错了,我试过了 google 找不到任何有用的 solution.Please 帮助我。

最佳答案可能是:

你为什么要关心?选择可读性最高的那个。不可读的代码需要人们花更多的时间来理解,快几毫秒的好处并不重要。如果这么小的性能问题很重要,你应该写汇编。

He told me 3rd one is the fastest and 2nd is equivalent to it and the 1st one is slowest.

不是真的。现代浏览器确实优化了所有三个循环,以至于它们实际上 运行 具有相同的速度。