JSFiddle - React, Tailwind, and code Playground

by vbelknap

JavaScript

var person = {}; //this makes it so it exists, now can add properties or do it right away

person.name = 'Bob';

person.occupation = 'Cowboy';

person.getOccupation = function(){
 	return person.occupation;   
}


//-----------------------------------------------

var people = { //use a variable to assign an object
    
    person1 : {
    	name: 'bob'
    }, //key and value have to be separated by :, with a comma between each one
	
    person2 : {
       	name: 'cindy'
	},

	getPerson: function(whichPerson) {
        switch(whichPerson) {
            case 1:
                return people.person1.name;
                break; //this will break it out of the switch if person1 is chosen
            case 2:
                return people.person2.name;
                break;
        }
	}

}; 



document.write( people.getPerson(2) );

//document.write(person.getOccupation() );
//if leave as document.write(person.getOccupation) will literally put out the entire function. Need additional () in order to get the results

//delete person.occupation;

console.log(person);