LoginSignup
3
1

More than 5 years have passed since last update.

es6での変数の値入れ替え

Posted at

変数の値入れ替え。忘れないようにメモ。

es5

var a = 1;
var b = 2;

var tmp = a;
a = b;
b = tmp;
// => a: 2, b: 1
es6
let a = 1;
let b = 2;
[b, a] = [a, b];
// => a: 2, b: 1

配列の分割代入を利用する。

3
1
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
3
1