Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
if文のはなし
tky
March 22, 2019
Programming
1
380
if文のはなし
tky
March 22, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
読みやすいコードを書こう
yutorin
0
440
mrubyを1300円のボードで動かそう
yuuu
0
190
byte列のbit表現を得るencodingライブラリ作った
convto
1
210
Licences open source : entre guerre de clochers et radicalité
pylapp
2
380
dbtとBigQueryで始めるData Vault入門
kazk1018
0
250
Update from the Elixir team - 2022
whatyouhide
0
200
Better Reliability through Observability (and Experimentation)
ksatirli
PRO
1
380
Explore Java 17 and beyond
josepaumard
3
680
既存画面の Jetpack Composeでの書き換え: FAANSでの事例紹介 / Case study of rewriting existing screens with Jetpack Compose
horie1024
0
360
Loom is Blooming
josepaumard
3
570
WindowsコンテナDojo:第2回 Windowsコンテナアプリのビルド、公開、デプロイ
oniak3ibm
PRO
0
160
Hapticをカスタマイズしてみよう / ZOZO Tech Talk #6 Customize Haptic
endoumari
0
370
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
324
54k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
236
1M
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
37
3.2k
Rails Girls Zürich Keynote
gr2m
86
12k
The Invisible Customer
myddelton
110
11k
The Straight Up "How To Draw Better" Workshop
denniskardys
225
120k
It's Worth the Effort
3n
172
25k
The Illustrated Children's Guide to Kubernetes
chrisshort
14
35k
Facilitating Awesome Meetings
lara
29
3.9k
The Language of Interfaces
destraynor
148
20k
What’s in a name? Adding method to the madness
productmarketing
11
1.5k
Design by the Numbers
sachag
271
17k
Transcript
if文のはなし @ticktakclock
自己紹介 • 竹中貴哉 @ticktakclock • React, Cordova • javascript 始めて
6 ヶ月経ちました • 本業は Android
if ...
const str = 'we are javascripters'; console.log(`length: ${str.length}`); if (str.length
> 0) { // true console.log('ok'); } // > length: 20 // > ok
const str = 'we are javascripters'; if (str.startsWith('we')) { //
true console.log('ok'); } // > ok
if文はtrue/falseで判定するんだ!
const str = 'we are javascripters'; console.log(str); if (str) {
console.log('ok'); } // > we are javascripters // > ok
const str = 'we are javascripters'; console.log(str); if (str !==
null) { console.log('ok'); } // > we are javascripters // > ok
const str = 'we are javascripters'; console.log(str); if (str) {
console.log('ok'); } // > we are javascripters // > ok
ドキュメント https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/if...else#Syntax
truthy? falsy?
truthy https://developer.mozilla.org/ja/docs/Glossary/truthy
const str = 'we are javascripters'; console.log(str); if (str !==
null) { console.log('ok'); } // > we are javascripters // > ok
const str = 'we are javascripters'; console.log(str); if (str) {
console.log('ok'); } // > we are javascripters // > ok
やってみた console.log(0 ? 'truthy' : 'falsy'); // falsy console.log(1 ?
'truthy' : 'falsy'); // truthy console.log(-1 ? 'truthy' : 'falsy'); // truthy console.log('' ? 'truthy' : 'falsy'); // falsy console.log('test' ? 'truthy' : 'falsy'); // truthy console.log(undefined ? 'truthy' : 'falsy'); // falsy console.log(null ? 'truthy' : 'falsy'); // falsy console.log('undefined' ? 'truthy' : 'falsy'); // truthy console.log(new Date() ? 'truthy' : 'falsy'); // truthy
まとめ if文の条件式は何でも入る
string https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,% 20June%201997.pdf
おしまい
string https://developer.mozilla.org/ja/docs/Web/JavaScript/Data_structures#Strings
var str = ''; console.log(str[0]); // undefined console.log(str.length); // 0
console.log(str.charCodeAt(0)); // NaN str = '\0'; console.log(str[0]); // ’ ’ console.log(str.length); // 1 console.log(str.charCodeAt(0)); // 0