0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

React 型宣言について

Last updated at Posted at 2021-08-30

const

###使用例

Const
const c = 1.23;

c = 5; //エラーが発生

特徴

  • 変数の再代入が禁止されている
  • 明らかな定数などには積極的に使用した方がよい

var と let

使用例

varAndLet

if(true){
    var v = 1.23
    let l = 4.56
}

console.log(v) //表示される
console.log(l) //エラーが発生

特徴

  • varとletは変数の再代入が可能
  • letはvarに比べてスコープが短い(同じ階層でしか生きられない)
  • 出来る限りletを使うことで可読性が高くなる

まとめ

型宣言にはそれぞれのケースに合わせたものがある。

コードの読み手に変数や定数のニュアンスを伝えるために、適切な型宣言を行う事をを意識したい。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?