kenvantruong
6/3/2018 - 3:23 AM

Objects

const hero = {
      name: 'Bruce Wayne',
      alias: 'Batman',
      catchphrase: 'To the Batcave!',
      speak: function() {
        return 'Attention! ' + this.catchphrase;
      },
      attack: function(sound) {
        // return '(punches bad guy) ' + sound;
        return `(punches bad guy) ${sound}`;
      }
    };

    // access a property
    const thingToLookFor = 'alias';

    console.log(hero.name); // Bruce Wayne
    console.log(hero['name']); // Bruce Wayne
    console.log(hero[thingToLookFor]); // Batman

    // accessing methods (functions)
    console.log(hero.speak);
    console.log(hero.speak());
    console.log(hero.attack('POWWWWW'));

    'this is my string'.toUpperCase();