Sunil Sunil - 4 months ago 7
Javascript Question

How to check the objects created in developer console?

I have the below script which creates a person object using constructor function.




function Person(firstName, lastName) {
var f = firstName;
var l = lastName;
}
var person = new Person("a", "b");





When I check in developer console in chrome it does not show the person object created. How to check the same?

Answer

JS

function Person(firstName, lastName) {
    this.firstName = firstName;
    this.lastName= lastName;
}
var person = new Person("a", "b");
console.log(person)

window.x = person 
window.x.firstName