LoginSignup
0
0

JavaScript の分割代入で変数名を変更する

Posted at

JavaScript の分割代入についての学習メモ。

詳細

これができるのは知っていた。

const obj = { a: 42, b: true };
const { a, b } = obj;

console.log(a); // 42
console.log(b); // true

これができるのは知らなかった。

const obj = { a: 42, b: true };
const { a: foo, b: bar } = obj;

console.log(foo); // 42
console.log(bar); // true

もちろん TypeScript でも動作する
https://typescriptbook.jp/reference/values-types-variables/object/destructuring-assignment-from-objects#%E4%BB%A3%E5%85%A5%E3%81%99%E3%82%8B%E5%A4%89%E6%95%B0%E5%90%8D%E3%81%AE%E6%8C%87%E5%AE%9A

まとめ

JavaScript,TypeScript では分割代入の際に変数名を変更できる。

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