v8 JavaScript performance implications of const, let, and var?

前端 未结 4 1227
鱼传尺愫
鱼传尺愫 2020-12-02 13:50

Regardless of functional differences, does using the new keywords \'let\' and \'const\' have any generalized or specific impact on performance relative to \'var\'?

A

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 14:45

    "LET" IS BETTER IN LOOP DECLARATIONS

    With a simple test (5 times) in navigator like that:

    // WITH VAR
    console.time("var-time")
    for(var i = 0; i < 500000; i++){}
    console.timeEnd("var-time")
    

    The mean time to execute is more than 2.5ms

    // WITH LET
    console.time("let-time")
    for(let i = 0; i < 500000; i++){}
    console.timeEnd("let-time")
    

    The mean time to execute is more than 1.5ms

    I found that loop time with let is better.

提交回复
热议问题