Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JavaScriptのnullとundefinedの違い
Search
Retasusan
May 29, 2025
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JavaScriptのnullとundefinedの違い
Kyoto Tech Talk #8
学生LT枠
Retasusan
May 29, 2025
More Decks by Retasusan
See All by Retasusan
公式サンプルが コンパイルできない 〜tracing::info! のエラーから Rust のマクロを読む〜
retasusan
0
90
Other Decks in Programming
See All in Programming
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
160
Next.js: The final boss of Web Performance
guaca
0
260
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
0
1.5k
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
590
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Discover your Explorer Soul
emna__ayadi
2
1.3k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
Designing for Performance
lara
612
70k
Balancing Empowerment & Direction
lara
6
1.3k
The untapped power of vector embeddings
frankvandijk
2
1.9k
Between Models and Reality
mayunak
4
500
Design in an AI World
tapps
1
350
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
Chasing Engaging Ingredients in Design
codingconduct
0
360
Transcript
JavaScript の nullとundefined の違い それっぽくそれなりに @Retasusan 2025/5/29 kyoto tech talk
自己紹介 • @Retasusan ◦ @retasusan_510 • 普段は大学生 ◦ 最近レポートが苦しい… •
Ruby on RailsとViteで アプリを作っている • 昨日クロスバイク購入 現実の姿 インターネットの姿
縦置きされる自転車
nullとundefined を 使い分けていますか?
そもそもnullとundefinedって何? • null ◦ プリミティブ型の一つ ◦ リテラル ◦ 代入すべき値が存在しないこと明示するときに使われがち? https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/null
• undefined ◦ プリミティブ型の一つ ◦ グローバルオブジェクトのプロパティ ◦ 値が代入されていない時とかに使われる? https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/undefined
いろんな関数で比較してみた • nullとundefined、引数なしを渡した時の関数の挙動の違い
typeof演算子
typeof演算子 • 引数がなし ◦ undefined • undefined ◦ undefined •
null ◦ object
等価演算子・厳密等価演算子
等価演算子・厳密等価演算子 • 等価演算子 ◦ 暗黙の型変換でnullと undefinedが等しく扱われる • 厳密等価演算子 ◦ 引数なしとundefinedは
等しい ◦ nullは等しくない
デフォルト引数
デフォルト引数 • 引数がなし、undefined ◦ デフォルト値 • null ◦ null
ちょっと有名なやつ
isNaN関数
isNaN関数 • 引数なし(undefined), undefined ◦ true(NaN) • null ◦ false(数値)
• 数値 + undefined ◦ true(NaN) • 数値 + null ◦ false(数値) • 数値 ◦ false(数値)
isNaN関数(余談)
isNaN関数(余談) • 真偽値と文字列の数値 ◦ false(数値になる) • NaN ◦ true •
NaN === NaN ◦ false ◦ 等価演算子だと比較できないから isNaN関数がある
Number関数
Number関数 • 引数なし ◦ 0 • null ◦ 0 •
undefined ◦ NaN • これがisNaN関数の中で動いてる
なんか意外だったやつ
JSON.stringify()
JSON.stringify() • 通常のJSオブジェクト ◦ nullとundefinedを保持 • JSONオブジェクト ◦ undefinedは無効な値 ◦
プロパティごと無視される • JSON配列 ◦ undefinedはnullに置換され る
Date関数
Date関数 • 引数なし ◦ 現在時刻 • null ◦ UNIXエポック •
undefined ◦ Invalid Date
まとめ • nullとundefinedでは挙動が違うことがよくある • undefinedと引数なしは同じ挙動のことが多い ◦ 稀に違う
JavaScript の nullとundefined の違い それっぽくそれなりに @Retasusan 2025/5/29 kyoto tech talk