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 1 year has passed since last update.

【Javascript】6.変数

Posted at

前提知識

変数は数字や文字列を格納しておく箱

1.変数は値の意味を明示できる*値の意味はAとBはどちらがわかりやすい?

A
let snack = 120
let tax = 1.08
console.log(snack * tax) //console.logは( )に入れた値を表示
B
console.log(120 * 1.08) //console.logは( )に入れた値を表示

Aの方はお菓子の値段を消費税でかけた額というのが見たらわかるようになるね

2.変更が簡単

A
// 1995年には消費税が5%です
let snack = 120
let tax = 1.05
console.log(snack * tax) // 5%の時の消費税が表示される
// 2020年には消費税が10%です
tax = 1.10
console.log(snack * tax) // 10%の時の消費税が表示される
B
console.log(120 * 1.08) console.log(snack * tax) // 5%の時の消費税が表示される

console.log(120 * 1.10) // 10%の時の消費税が表示される

Aの場合は数字を変更するときに変数を変えるだけだが、Bの場合は値そのものを変更しなければならない

3つの変数

*let
*const
*var
上記は後日説明

0
0
0

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?