Upgrade to Pro — share decks privately, control downloads, hide ads and more …

if文のはなし

03489323ab951eff5e8f0d0cd7ccc250?s=47 tky
March 22, 2019

 if文のはなし

03489323ab951eff5e8f0d0cd7ccc250?s=128

tky

March 22, 2019
Tweet

Other Decks in Programming

Transcript

  1. if文のはなし @ticktakclock

  2. 自己紹介 • 竹中貴哉 @ticktakclock • React, Cordova • javascript 始めて

    6 ヶ月経ちました • 本業は Android
  3. if ...

  4. const str = 'we are javascripters'; console.log(`length: ${str.length}`); if (str.length

    > 0) { // true console.log('ok'); } // > length: 20 // > ok
  5. const str = 'we are javascripters'; if (str.startsWith('we')) { //

    true console.log('ok'); } // > ok
  6. if文はtrue/falseで判定するんだ!

  7. const str = 'we are javascripters'; console.log(str); if (str) {

    console.log('ok'); } // > we are javascripters // > ok
  8. const str = 'we are javascripters'; console.log(str); if (str !==

    null) { console.log('ok'); } // > we are javascripters // > ok
  9. const str = 'we are javascripters'; console.log(str); if (str) {

    console.log('ok'); } // > we are javascripters // > ok
  10. ドキュメント https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/if...else#Syntax

  11. truthy? falsy?

  12. truthy https://developer.mozilla.org/ja/docs/Glossary/truthy

  13. const str = 'we are javascripters'; console.log(str); if (str !==

    null) { console.log('ok'); } // > we are javascripters // > ok
  14. const str = 'we are javascripters'; console.log(str); if (str) {

    console.log('ok'); } // > we are javascripters // > ok
  15. やってみた 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
  16. まとめ if文の条件式は何でも入る

  17. string https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,% 20June%201997.pdf

  18. おしまい

  19. string https://developer.mozilla.org/ja/docs/Web/JavaScript/Data_structures#Strings

  20. 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