NaN
とは
- 数値ではない、特別な値.
isNaN()
でNaN
かどうかを調べることが可能.Number.isNaN(NaN)
の場合は、引数がNaN
である場合のみ、true
が返される.Object.is(value, NaN)
型変換
console.log(true + 3 + '100' + null); // 4100null
Includes()
- 第2引数に、
fromIndex
がある場合は、第1引数のsearchElement
のどのIndexから検索を始めるか指定する.
const pets = ['cat', 'dog', 'bat', 'bird', 'pet']; console.log(pets.includes('bat', 3)); // Expected output: false
配列のコピー
- 参照渡し:
const array2 = array1;
のパターン.
- 値渡し:
array.slice()
、array.concat()
nth-child
li
の何個目の項目なのかを指定する際に使用.
<ul> <li>項目1</li> <li>項目2</li> <li>項目3</li> <li>項目4</li> <li>項目5</li> <li>項目6</li> <li>項目7</li> <li>項目8</li> </ul>
li:nth-child(5) { background: red; }
画像のプレビュー
FileReader
とreadAsDataURL
で実装.readAsDataURL(blob)
は、Fileオブジェクト.
okinawanpizza.hatenablog.com
developer.mozilla.org
Node.js WebSocket
// WebSocketのサーバの生成 let ws = require('ws') var server = new ws.Server({port:5001}); // 接続時に呼ばれる server.on('connection', ws => { // クライアントからのデータ受信時に呼ばれる ws.on('message', message => { console.log(message); // クライアントにデータを返信 server.clients.forEach(client => { client.send(message); }); }); // 切断時に呼ばれる ws.on('close', () => { console.log('close'); }); });
JSON 属性へのアクセス
{ "squadName": "Super hero squad", "homeTown": "Metro City", "formed": 2016, "secretBase": "Super tower", "active": true, }
superHeroes.homeTown superHeroes['active']
複数の関数をExport
- 名前付きで行う.
- デフォルトは1つのみ.
qiita.com
// 名前つきexport export { setPerimeter, getPerimeter, squareRoot, determineArea }
pushstate
- 引数が複数必要.
const state = { page_id: 1, user_id: 5 }; const url = "hello-world.html"; history.pushState(state, "", url);
foreach()
- 引数は、
item
,index
の順.
customers.forEach((item, index) => displayCustomer(index+1, item));
セマンティックバージョン
^
の場合.
^1.2.3 => 1.2.3 <= version < 2.0.0 ^0.13.0 => 0.13.0 <= version < 0.14.0
0.xの場合とそれ以外とでルールが異なるので注意。
~
の場合.
- 複数のバージョンの選択肢がある場合、最新が選択される.
~1.2.3 => 1.2.3 <= version < 1.3.0 ~1.2 => 1.2.0 <= version < 1.3.0, 1.2.xと同じ。 ~1 => 1 <= version < 2, 1.xと同じ。