美文网首页
【JavaScript】let v.s. const

【JavaScript】let v.s. const

作者: 盐果儿 | 来源:发表于2024-03-26 21:45 被阅读0次

    let keyword is used to declare a block-scoped variable that can be reassigned a new value. Unlike variables declared with const, variables declared with let can have their values changed or updated.

    const keyword is used to declare a variable with a constant (unchanging) value. When you declare a variable using const, you cannot reassign a new value to it later in the code. This helps prevent accidental reassignment and adds clarity to the code by indicating that the variable's value should remain constant.

    Example:

    const handleSave = () {}

    When an arrow function is assigned to the variable handleSave, the function it assigned cannot change, but the logic of the code, the state, and the return value can be changed. So we use const when defining an arrow function.

    Sometimes:

    When we say the behavior of a function, it refers to the actions or logic performed by the function.

    相关文章

      网友评论

          本文标题:【JavaScript】let v.s. const

          本文链接:https://www.haomeiwen.com/subject/gpqetjtx.html