InterviewSolution
| 1. |
What Is User-defined Objects? |
|
Answer» User-Defined Objects: All user-defined objects and built-in objects are descendants of an object called Object. The new Operator: The new operator is used to create an instance of an object. To create an object, the new operator is followed by the constructor method. In the following example, the constructor methods are Object(), ARRAY(), and Date(). These constructors are built-in JavaScript FUNCTIONS. var employee = new Object(); The Object() Constructor: A constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable. The variable contains a REFERENCE to the new object. The properties assigned to the object are not variables and are not defined with the var keyword. Example 1: Try the following example; it demonstrates how to create an Object. <html> User-Defined Objects: All user-defined objects and built-in objects are descendants of an object called Object. The new Operator: The new operator is used to create an instance of an object. To create an object, the new operator is followed by the constructor method. In the following example, the constructor methods are Object(), Array(), and Date(). These constructors are built-in JavaScript functions. var employee = new Object(); The Object() Constructor: A constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable. The variable contains a reference to the new object. The properties assigned to the object are not variables and are not defined with the var keyword. Example 1: Try the following example; it demonstrates how to create an Object. <html> |
|