LoginSignup
0
0

More than 3 years have passed since last update.

JavaScript: 変数の値を交換する(配列の分割代入を使う)

Posted at

ES2015の機能を使うとシンプルに書ける。

> let x = 2, y = 3;
undefined
> [x, y] = [y, x]  # ここ
[ 3, 2 ]
> x
3
> y
2
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