OBJECTS Flashcards
1) An object is a composite value?:-
it aggregates multiple values (primitive values or other objects) and allows you to store and retrieve those values by name.
- An object is an unordered collection of properties, each of which has a name and a value.
2) Property names are usually strings (although, as we’ll see in later, property names can also be Symbols), so we can say that objects map strings to values. This string-to-value mapping goes by various names?:-
—> you are probably already familiar with the fundamental data structure under the name “hash,” “hashtable,” “dictionary,” or “associative array.” However, an object is more than a simple string-to-value map.
3) In addition to maintaining its own set of properties, a JavaScript object also inherits?:-
the properties of another object, known as its “prototype.” The methods of an object are typically inherited
properties, and this “prototypal inheritance” is a key feature of JavaScript.
4) JavaScript objects are dynamic?:—
properties can usually be added and deleted—but they can be used to simulate the static objects and “structs” of statically typed languages. They can also be used (by ignoring the value part of the string-to-value mapping) to represent sets of strings.
5) Any value in JavaScript that is not a string, a number, a Symbol, or true, false, null, or undefined is an object.
And even though strings, numbers, and booleans are not objects, they can behave like?:-
immutable objects.
6) Recall that objects are mutable and manipulated by reference rather than by value. If the variable x refers to an object and the code let y = x; is executed, the variable y holds a reference to the same object, not a?:-
copy of that object. Any modifications made to the object through the variable y are also visible through the variable x.
7) It is sometimes important to be able to distinguish between properties defined directly on an object and those that are inherited from a prototype object. JavaScript uses the term?:-
own property to refer to non-inherited properties.
8) In addition to its name and value, each property has three property attributes:
-> The writable attribute specifies whether the value of the property can be set.
-> The enumerable attribute specifies whether the property name is returned by a for/in loop.
-> The configurable attribute specifies whether the property can be deleted and whether its attributes can be
altered.
9) Many of JavaScript’s built-in objects have properties that are read-only, non-enumerable, or non-configurable. By default, however, all properties of the objects you create are?:-
writable, enumerable, and configurable.
10) There are three ways object can be created in js, list them?:-
-> objects can be created with object literals,
-> with the new(The new operator creates and initializes a new object) keyword, and
-> with the Object.create() function.
11) The easiest way to create an object is to include an object literal in your JavaScript code. In its simplest form, an object literal is a?:-
comma-separated list of colon-separated name:value pairs, enclosed within curly braces.
12) A property name is a JavaScript __________. A property value is any JavaScript __________?:-
-> identifier or a string literal (the empty string is allowed)
-> expression - the value of the expression (it may be a primitive value or an object value) becomes the value of the property.
13) The new operator creates and initializes a new object. The new keyword must be followed by a?:-
function invocation. A function used in this way is called a constructor and serves to initialize a newly created
object.
JavaScript includes constructors for its built-in types. For example:
let o = new Object(); // Create an empty object: same as {}.
let a = new Array(); // Create an empty array: same as [].
let d = new Date(); // Create a Date object representing the current time
let r = new Map(); // Create a Map object for key/value mapping
14) Almost every JavaScript object has a second JavaScript object associated with it. This second object is known as?:-
a prototype, and the first object inherits properties from the prototype.
15) All objects created by object literals have the same prototype object, and we can refer to this prototype object in JavaScript code as?:-
Object.prototype.