Skip to content

Instantly share code, notes, and snippets.

@xiaoyunyang
Created September 18, 2019 17:31
Show Gist options
  • Select an option

  • Save xiaoyunyang/3d0e0027602980f4dc9d22b8c076ebe2 to your computer and use it in GitHub Desktop.

Select an option

Save xiaoyunyang/3d0e0027602980f4dc9d22b8c076ebe2 to your computer and use it in GitHub Desktop.

Revisions

  1. xiaoyunyang created this gist Sep 18, 2019.
    39 changes: 39 additions & 0 deletions let-v-var.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    function foo() {
    let res = ''
    let j = 10

    for(let i=0; i<j; i++) {
    // uncommenting ... the following line causes error
    // var j = 5
    res += `${j}, `
    j -= 1
    }
    res += `${j}`
    console.log(`foo: ${res}`)
    }

    function bar() {
    let res = ''
    let j = 10

    for(let i=0; i<j; i++) {
    let j = 5
    res += `${j}, `
    j -= 1
    }
    res += `${j}`
    console.log(`bar: ${res}`)
    }

    function baz() {
    let res = ''
    var j = 10

    for(let i=0; i<j; i++) {
    var j = 5
    res += `${j}, `
    j -= 1
    }
    res += `${j}`
    console.log(`baz: ${res}`)
    }