Object Literals & Constructors
Video
JavaScript Notes
JavaScript
let obj1 = {
a: "this",
b: "is",
c: "an",
d: "object",
e: "literal"
};
let obj2 = new Object(["object", "contructor", "one"]); // new Array("", "", "")
let obj3 = new Object({ an: "object", literal: "again" });
let obj4 = new Object(obj1.a); // new Object("some string") or new String("asdfas")
let obj5 = new Object(); // same as new Object(null) or new Object(undefined)
let obj6 = new Object(true); // new Boolean(true)
console.log(
"OBJ1",
obj1,
typeof obj1,
obj1 instanceof Object,
obj1.constructor,
"\n"
);
console.log(
"OBJ2",
obj2,
typeof obj2,
obj2 instanceof Array,
obj2 instanceof Object,
Array.isArray(obj2),
obj2.constructor,
"\n"
);
console.log(
"OBJ3",
obj3,
typeof obj3,
obj3 instanceof Object,
obj3.constructor,
"\n"
);
console.log(
"OBJ4",
obj4,
typeof obj4,
obj4 instanceof String,
obj4.constructor,
"\n"
);
console.log(
"steve",
String("steve"),
new String("steve"),
typeof "steve",
typeof String("steve"),
typeof new String("steve"),
"\n"
);
console.log(
"OBJ5",
obj5,
typeof obj5,
obj5 instanceof Object,
obj5.constructor,
"\n"
);
console.log(
"OBJ6",
obj6,
typeof obj6,
obj6 instanceof Boolean,
obj6 instanceof Object,
obj6.constructor,
"\n"
);
Feedback
Submit and view feedback