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

if文のはなし

tky
March 22, 2019

 if文のはなし

tky

March 22, 2019
Tweet

Other Decks in Programming

Transcript

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

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

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

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

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

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

    console.log('ok'); } // > we are javascripters // > ok
  7. やってみた 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
  8. 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