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
JavaScriptのnullとundefinedの違い
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Retasusan
May 29, 2025
Programming
0
110
JavaScriptのnullとundefinedの違い
Kyoto Tech Talk #8
学生LT枠
Retasusan
May 29, 2025
Tweet
Share
Other Decks in Programming
See All in Programming
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
200
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
AI & Enginnering
codelynx
0
110
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
組織で育むオブザーバビリティ
ryota_hnk
0
170
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
640
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
今から始めるClaude Code超入門
448jp
7
8.5k
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
AtCoder Conference 2025
shindannin
0
1k
CSC307 Lecture 07
javiergs
PRO
0
550
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
Featured
See All Featured
Discover your Explorer Soul
emna__ayadi
2
1.1k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Code Reviewing Like a Champion
maltzj
527
40k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
55
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
100
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
580
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
77
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
3.9k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
410
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
The agentic SEO stack - context over prompts
schlessera
0
630
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