【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.

版权声明:
作者:Mr李
链接:https://www.techfm.club/p/118107.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>