Objects

Estimated reading: 1 minute 77 views

There are several ways to create objects in JavaScript:

				
					const person = {
  name: 'John',
  age: 30,
  city: 'New York'
};

				
			
				
					 var myObject = {
 sayHello : function() {
 console.log(’hello’);
 },
 myName : ’Rebecca’
 };
 myObject.sayHello();
 // logs ’hello’
 console.log(myObject.myName);
 // logs ’Rebecca’
				
			
Share this Doc

Objects

Or copy link