【JavaScript】let v.s. const
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.
共有 0 条评论