kajirikajiri(wsl2)
gh-pages
gh-pages
  • Initial page
  • 🍳😋🎵
    • githubの新しい使い方
    • itunes miniplayer 前面固定(windows)
    • force darkmode chrome and disable white flash
    • wsl2 色 変更
    • quaker oats
    • 圧力鍋 ホイル焼き
  • 💪💪🏻💪🏼🦾💪🏽💪🏾💪🏿
    • gh-openの改造
    • GraphQL
  • gh-open not working with wsl2
  • react hook を5分で使う
  • 5分でLambda Storeをつかってみた
  • 実働環境で色々updateして得た知見 vue nuxt vuetify
  • dexie firebase nuxt vuetifyでオフラインpwaメモ帳作った
  • worker api batch
  • docker run syntax error
  • webpack babel
  • chainer?
  • nuxtjs firebase ui window is not defined
  • nuxt firebaseui ui broken
  • typescript 導入 実働 既存 環境
  • code-prettify nuxt
  • rustを動かしてみる
  • js 復習
  • vue The client-side rendered virtual DOM tree
  • ApexChartsがSSRで描画されない
  • atcoder
  • gitbook Page build failure
  • globalThis
  • Promise.allSettled
  • export * as ns from "module"
  • matchAll
  • js nullish
  • nullish optional chaining
  • nullish node 14 vs 13
  • nodenv global not working
GitBook提供
このページ内

役に立ちましたか?

nullish optional chaining

前へjs nullish次へnullish node 14 vs 13

最終更新 5 年前

役に立ちましたか?

const adventurer = {
  name: 'Alice',
  cat: {
    name: 'Dinah'
  }
};

const dogName = adventurer.dog?.name;
console.log(dogName);
// expected output: undefined

console.log(adventurer.someNonExistentMethod?.());
// expected output: undefined

便利じゃんこれ

rubyの&ね。ぱくりか。いやrubyもパクリか?

typescriptはコンパイル時にnullチェックできる

optional chainingはnull, undefinedならundefinedを返す。これってつないだら、どこまでもいけるって、それはそれで大丈夫?

const adventurer = {
  name: 'Alice',
  cat: {
    name: 'Dinah'
  }
};

const dogName = adventurer.dog?.name?.hoge?.koge;
console.log(dogName);


console.log(adventurer.someNonExistentMethod?.());


// > undefined
// > undefined

なんかな、、、

 いいことあるのかな

しかし、Optional chaining を使うことで上記のコードを簡潔に書くことができます。

let id = null;
if (user) {
  id = user.id;
}
``````````````````````````
const id = user?.id;

なるほどたしかに

オプショナルチェーン (?.) - JavaScript | MDN
Node.js v14の主な変更点 - 別にしんどくないブログ別にしんどくないブログ
Node.js v14の主な変更点 - 別にしんどくないブログ別にしんどくないブログ
Logo
Logo
Logo