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

JavaScriptのわかりずらかったことメモ

Last updated at Posted at 2021-01-03

Javascriptでわかりずらかったことのメモです。

##可変引数

コード
function test(...args) {
    console.log(args);
}

test("1", "2");
結果
[ '1', '2' ]

##論理演算子と代入

コード
var a = "1";
var b = "2";

var c = a && b;
console.log(c);

var d = a || b;
console.log(d);
結果

2
1

a && bは!a ? a : b; と同じ。
a || bはa ? a : b; と同じ。

こちらを参考
https://qiita.com/masakazu_ca/items/3ce9228a6c009499cb79

##キーの名前でメソッド的

コード
var map = {a:"1"};
console.log(map.a);
結果
1

##変数名がキー名になる

var b = "2";
console.log({a:"1",b});
結果
{ a: '1', b: '2' }

##ドット三つの奴を使う

ドット三つを使うコード
var b = {'B': { "C": 'Cのvalue', }};
console.log({a:"Aのvalue",...b});
結果
{ a: 'Aのvalue', B: { C: 'Cのvalue' } }

ドット三つの奴を使わないと

ドット三つを使わないコード
var b = {'B': { "C": 'Cのvalue', }};
console.log({a:"Aのvalue",b});
結果
{ a: 'Aのvalue', b: { B: { C: 'Cのvalue' } } }

##letとvarの違い

varは再宣言可能
letは再宣言不可

varのコード
var a = "1";
var a = "2";

console.log(a);
結果
2
letのコード
let a = "1";
let a = "2"; // letで宣言された変数名はスコープ内に一つだけ

console.log(a);
結果
ERROR:
let a = "2";
    ^

こちらを参考。
https://qiita.com/y-temp4/items/289686fbdde896d22b5e

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