Home  >  Q&A  >  body text

javascript - let declare variables

let will not have variable promotion; if I use let before declaration, the browser should report an error; but my printout is undefined; is it my understanding or my writing error?

某草草某草草2686 days ago756

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-06-12 09:31:34

    ErrorUncaught ReferenceError: a is not defined means the variable is undefined, not that the variable is undefined. If the value of the variable variable is undefined, then console.log(variable) should output undefined and should not report an error.

    reply
    0
  • 学习ing

    学习ing2017-06-12 09:31:34

    Variables declared by let and const will not be declared in advance, which means that the variables are not accessible before the runtime execution context is lexically bound.

    function foo(){
    |
    | not accessible
    |
    let a = 1
    }

    reply
    0
  • PHP中文网

    PHP中文网2017-06-12 09:31:34

    The second line of code here makes no sense

    The first line prints. When printing,
    because it is let, not define because it is not improved.
    The second line, let xxx, is not written, which should also be the error

    If it is var, it is undefined
    Because there is a promoted variable but it is not specified or copied

    reply
    0
  • Cancelreply