I am having a theory question in my mind while learning Java Script (OOP concepts), until now i have learn two of the following way in which we can define object and initialize it's property and set its value for eg:
// 1st method
var obj1 = {
name: "John",
middleName: "XYZ",
lastName: "David",
};
document.write(obj1.name + obj1.middleName + obj1.lastName);
In the above method the object : obj1 is defined using a keyword (var) which is use for declaring a variable but here we are using it to define an object.Now i know that this object is global and i can acces its property anywhere inside a function or outside a function but what concerns me that this object has no instance to refer (i.e we cannot use instanceof keyword for this object) since i am familar with "Java" language in which every object is an instance of it's class but in JavaScript its a different concept to understand in short my question is : What exactly does the above object is referring to or is this object initialized automatically even when there is no class declared for this object ?
//2nd method
var obj2 = new Person("David");
function Person(name)
{
document.write(name + " " + "is a person");
}
document.write(" ");
document.write(obj2 instanceof Person);
In second method the object : obj2 is an object of a function Person() again being familiar with "Java" concept i thought that the obj2 is an object of class Person and Person() being its constructor for the class Person in short my question is : How can an object be an instanceof a function without a class being declared first ?