Q
What is the output of console.log(person.greet()); if var person = {greet: function() {return 'Hello';}};?

Answer & Solution

Answer: Option A
Solution:
The greet method returns 'Hello', so console.log(person.greet()); outputs Hello.
Related Questions on Average

How do you access the value of the name property in the object var person = {name: 'John', age: 30};?

A). person['name']

B). person.name

C). person->name

D). person::name

How do you call a method from a parent class in a subclass in JavaScript ES6?

A). super.methodName()

B). this.methodName()

C). parent.methodName()

D). base.methodName()

What does Object.keys(person) return if var person = {name: 'John', age: 30};?

A). ['name', 'age']

B). ['John', 30]

C). {'name', 'age'}

D). {'John', 30}

What is the correct way to create an object in JavaScript?

A). var obj = {};

B). var obj = [];

C). var obj = ();

D). var obj = {};

How do you create an instance of the Car object using the constructor function?

A). var myCar = new Car('Toyota', 'Corolla');

B). var myCar = Car('Toyota', 'Corolla');

C). var myCar = create Car('Toyota', 'Corolla');

D). var myCar = construct Car('Toyota', 'Corolla');

How can you delete the age property from the person object?

A). delete person.age;

B). remove person.age;

C). person.age = null;

D). person.age.delete;

How do you add a method to an object created with a constructor function?

A). this.methodName = function() {}

B). this.methodName: function() {}

C). this.methodName = () {}

D). this.methodName: () {}

How can you check if the age property exists in the person object?

A). 'age' in person

B). person.has('age')

C). person.contains('age')

D). person.hasOwnProperty('age')

What will console.log(car.make); output if var car = {make: 'Toyota', model: 'Corolla'};?

A). Toyota

B). Corolla

C). Undefined

D). Error

What will the following code output? console.log(person['age']); if var person = {name: 'John'};

A). 30

B). John

C). undefined

D). null