if文のはなし
by
tky
×
Copy
Open
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
if文のはなし @ticktakclock
Slide 2
Slide 2 text
自己紹介 ● 竹中貴哉 @ticktakclock ● React, Cordova ● javascript 始めて 6 ヶ月経ちました ● 本業は Android
Slide 3
Slide 3 text
if ...
Slide 4
Slide 4 text
const str = 'we are javascripters'; console.log(`length: ${str.length}`); if (str.length > 0) { // true console.log('ok'); } // > length: 20 // > ok
Slide 5
Slide 5 text
const str = 'we are javascripters'; if (str.startsWith('we')) { // true console.log('ok'); } // > ok
Slide 6
Slide 6 text
if文はtrue/falseで判定するんだ!
Slide 7
Slide 7 text
const str = 'we are javascripters'; console.log(str); if (str) { console.log('ok'); } // > we are javascripters // > ok
Slide 8
Slide 8 text
const str = 'we are javascripters'; console.log(str); if (str !== null) { console.log('ok'); } // > we are javascripters // > ok
Slide 9
Slide 9 text
const str = 'we are javascripters'; console.log(str); if (str) { console.log('ok'); } // > we are javascripters // > ok
Slide 10
Slide 10 text
ドキュメント https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/if...else#Syntax
Slide 11
Slide 11 text
truthy? falsy?
Slide 12
Slide 12 text
truthy https://developer.mozilla.org/ja/docs/Glossary/truthy
Slide 13
Slide 13 text
const str = 'we are javascripters'; console.log(str); if (str !== null) { console.log('ok'); } // > we are javascripters // > ok
Slide 14
Slide 14 text
const str = 'we are javascripters'; console.log(str); if (str) { console.log('ok'); } // > we are javascripters // > ok
Slide 15
Slide 15 text
やってみた 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
Slide 16
Slide 16 text
まとめ if文の条件式は何でも入る
Slide 17
Slide 17 text
string https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,% 20June%201997.pdf
Slide 18
Slide 18 text
おしまい
Slide 19
Slide 19 text
string https://developer.mozilla.org/ja/docs/Web/JavaScript/Data_structures#Strings
Slide 20
Slide 20 text
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