inner const vs outer let

Edit on GitHub

loop performance - inner const vs outer let

Setup

let counter = 0

Tests

  • inner const

    for (let i = 0; i < 1000000; i++) {
      const x = Math.random()
      counter += x
    }
  • outer let

    let x = null
    
    for (let i = 0; i < 1000000; i++) {
      x = Math.random()
      counter += x
    }