Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
null or undefined
Search
Susisu
August 24, 2024
Programming
22
5.3k
null or undefined
https://kyoto-nanka.connpass.com/event/324686/
Susisu
August 24, 2024
Tweet
Share
More Decks by Susisu
See All by Susisu
Mackerel のフロントエンドフレームワーク移行 序章 / Hatena Engineer Seminar #13
susisu
0
2k
スクリーンショット撮影のために Puppeteer を操る / Kyoto.js 16
susisu
0
770
BuckleScript 使ってみた
susisu
0
270
Atom パッケージ開発のすゝめ
susisu
1
2k
5分でわかる Curry–Howard 同型対応
susisu
0
860
ジェネレータを有効活用し隊 / Kyoto.js 11 LT
susisu
2
2k
遅延評価と健康
susisu
0
570
楽しく学ぶ難解プログラミング言語
susisu
0
700
多分これが一番早いと思います
susisu
0
400
Other Decks in Programming
See All in Programming
Kotlin 2.0 and Beyond
antonarhipov
2
140
What we keep in mind when migrating from Serverless Framework to AWS CDK and AWS SAM
kasacchiful
1
130
Rustではじめる負荷試験
skanehira
5
1.2k
ウォンテッドリーにおけるモバイルアプリ開発 / iOSDC Japan 2024 Sponsor Session
kubode
0
230
数値を文字列に整形する際の落とし穴とその解決策(iOSDC2024 ルーキーズLT) / iOSDC Japan 2024 Formatting Floating-Point Numbers
glassfiber
0
250
BasicBasic認証
sadnessojisan
5
2.5k
長期運用プロダクトの開発速度を維持し続けるためのリファクタリング実践例
wataruss
8
2.6k
全力の跳躍を捉える計測アプリを作る
ogijun2018
0
1.1k
Desafios e Lições Aprendidas na Migração de Monólitos para Microsserviços em Java
jessilyneh
2
130
ESLint Rule により事業, 技術ドメインに沿った制約と誓約を敷衍させるアプローチのすゝめ
shinyaigeek
1
2.7k
Wallet API, Verifier APIで実現するIDカード on iPhoneの世界
shitamori1272
1
320
Swiftで高速フーリエ変換してオーディオビジュアライザーを作る / iOSDC Japan 2024 Day1 Track D
kyome22
2
460
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
508
110k
A Tale of Four Properties
chriscoyier
155
22k
Making Projects Easy
brettharned
113
5.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
24
2k
Scaling GitHub
holman
458
140k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
3k
Speed Design
sergeychernyshev
18
400
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
The Brand Is Dead. Long Live the Brand.
mthomps
53
37k
The Illustrated Children's Guide to Kubernetes
chrisshort
46
48k
Web Components: a chance to create the future
zenorocha
308
41k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
230
17k
Transcript
null or unde fi ned 2024-08-24 Kyoto.ͳΜ͔ #6 id:susisu
͜Μʹͪ • id:susisu • גࣜձࣾͯͳ WebΞϓϦέʔγϣϯΤϯδχΞ • ਓؒ ( TypeScript
| ESLint | Prettier )
JavaScript ͱ͍͑
null ͋Δ unde fi ned ͋Δ
Α͋͘Δઆ໌ • null: ͕ͳ͍ͱઃఆ͞Ε͍ͯΔ • unde fi ned: ͕ઃఆ͞Ε͍ͯͳ͍
ΫΠζΛ͖࣋ͬͯ·ͨ͠
ୈҰ
> const x = new Map([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); ???
> const x = new Map([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); undefined
ୈೋ
> const x = new Headers([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); ???
> const x = new Headers([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); null
> const x = new Headers([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); null 🤷
Α͋͘Δઆ໌ ≠ ݱ࣮ • null: ͕ͳ͍ͱઃఆ͞Ε͍ͯΔ • unde fi ned:
͕ઃఆ͞Ε͍ͯͳ͍
ݱ࣮ • લఏ: "JavaScript" ͍ͭ͘ͷඪ४༷͔ΒΓཱ͍ͬͯΔ • ECMAScript ͷݴޠ༷Ͱද͖΄΅ unde fi
ned ͕ΘΕΔ • ͨͩ͠ਖ਼نදݱ, JSON, ϓϩτλΠϓͷΈྫ֎తʹ null ͕ొ͢Δ • Web ؔ࿈༷ (DOM, Fetch ͳͲ) Ͱ׳ྫతʹ null ͕ΘΕΔ͜ͱ͕ଟ͍ • ҙຯతͳ͍͚ΑΓ, ΄΅༷͝ͱʹҰ؏ͯ͠ͲͪΒ͔Λ͏
ΫΠζ࠶։
ୈҰ
> const x = new Map([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); ???
> const x = new Map([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); undefined ECMAScript ͷݴޠ༷Ͱఆٛ
ୈೋ
> const x = new Headers([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); ???
> const x = new Headers([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); null Fetch Standard Ͱఆٛ
> const x = new URLSearchParams([["foo", "hello"]]); > x.get("foo"); "hello"
> x.get("bar"); null URL Standard Ͱఆٛ
ୈࡾ
> document.getElementById("nonexistent"); ???
> document.getElementById("nonexistent"); null DOM Standard Ͱఆٛ
ୈ࢛
> const xs = ["A", "B", "C"]; > xs.find((x) =>
x === "A"); "A" > xs.find((x) => x === "Z"); ???
> const xs = ["A", "B", "C"]; > xs.find((x) =>
x === "A"); "A" > xs.find((x) => x === "Z"); undefined ECMAScript ͷݴޠ༷Ͱఆٛ
ୈޒ
> const x = "ABC"; > x.match(/A/); ["A", ...] >
x.match(/Z/); ???
> const x = "ABC"; > x.match(/A/); ["A", ...] >
x.match(/Z/); null ECMAScript ͷݴޠ༷Ͱఆٛ ਖ਼نදݱྫ֎తʹ null
> /A/.exec("ABC"); ["A", ...] > /Z/.exec("ABC"); null
·ͱΊ • null ͱ unde fi ned ༷͝ͱʹ֓ͶҰ؏ͨ͠ΘΕํΛ͍ͯ͠Δ • ECMAScript
ͷݴޠ༷Ͱද͖΄΅ unde fi ned ͕ΘΕΔ • Web ؔ࿈༷Ͱ׳ྫతʹ null ͕ΘΕΔ͜ͱ͕ଟ͍ • ҙຯతʹ͍͚ΒΕ͍ͯΔ͜ͱ΄΅ͳͦ͞͏
͍͚ͷώϯτ • جຊ unde fi ned Λ͏ͷ͕͓͢͢Ί • ݴޠΈࠐΈͷػೳͱฒͯҧײ͕ग़ʹ͍͘ •
Web ͷ API , null Λ͏ϥΠϒϥϦʹڧؔ͘࿈͢Δ෦ͳΒ null Λͬͯ౷ҰײΛग़͢ͷΞϦ • ͳΜʹͤΑҰ؏͍ͨ͠ํ͕͞Ε͍ͯΔͷ͕Θ͔Γ͍ͩ͢Ζ͏
ࢀߟจݙ • ECMAScript® 2024 language speci fi cation • https://ecma-international.org/publications-and-standards/standards/
ecma-262/ • WHATWG Standards • https://spec.whatwg.org
ͳΜͰ͜ͷΛ? • ECMAScript ͷݴޠ༷ʹର͢Δ proposal Ͱ null ͕ΘΕ͍͔ͯͨΒ • https://github.com/arthur
fi orette/proposal-safe-assignment-operator • > The result should conform to the format [error, null | undefined] or [null, data]. • ͔֬ʹҙຯతʹؒҧ͍ͬͯͳ͍͕, ༷ͷҰ؏ੑతʹͲ͏?