JavaScript var, let, const: How to use variable declaration

Other language site
ja ja
Google Translate
  • -

    シェア
  • ---

    LINEで送る
  • -

    はてなブックマーク
    ブックマーク
  • -

    pocket
  • -

    rss
JavaScript logo

I decided to use JavaScript after a long time, and as I looked up, variations of variable declarations had increased.There seems to be a usage of let, const.

It was two years ago because it was formulated in ES 2015. Oh crap, it is considerably late. I examined it late.

var

It is conventional usage. Even if a new method is added, it can be used. However, when we prioritize using let, const explained later, we no longer use it.

I am no longer using it.

let

It is used with variables valid within the declared scope. It can be used as an alternative to the var you have used so far.

Since it also includes the meaning of limiting the scope, we recommend that you use this rather.

When declared in if, for, it becomes a valid variable only in the syntax. It is now possible to use variables with a narrow scope that has never been before.

const

It is used as a constant. Once you set the value you can not change it. It is used in situations such as storing DOM objects in variables.

SNS also distributes articles.
Leave a Reply

*

If you like this article, share it!