JavaScript: The Good Parts Flashcards
What is loose typing in JavaScript?
Loose typing means that JavaScript allows variables to hold values of different types, and the language automatically converts between types as needed.
What does it mean for functions to be first-class objects in JavaScript?
Functions as first-class objects means that functions can be assigned to variables, passed as arguments, and returned from other functions, just like any other data type.
What is prototypal inheritance in JavaScript?
Prototypal inheritance is a type of inheritance in which objects inherit directly from other objects, rather than inheriting from a class or blueprint.
What is the role of whitespace in JavaScript?
Whitespace is usually not significant and is ignored during execution.
What are objects in JavaScript?
Objects in JavaScript are collections of key-value pairs, where keys are strings and values can be any data type, including other objects, functions, and arrays.
How can objects be created in JavaScript?
Objects can be created using object literals, the new keyword with a constructor function, or the Object.create() method.
What is the prototype chain in JavaScript?
The prototype chain is a mechanism through which objects can inherit properties and methods from other objects, by having a reference to their prototype object.
What is inheritance in JavaScript?
Inheritance in JavaScript is a mechanism that allows objects to share properties and methods with other objects. JavaScript implements prototypal inheritance, where objects inherit directly from other objects.
What is a prototype object in JavaScript?
A prototype object is an object from which other objects can inherit properties and methods. Every JavaScript object has an internal reference to a prototype object, which forms a prototype chain that ultimately leads to the root object.
How can you set the prototype of an object in JavaScript?
You can set the prototype of an object by using the Object.create() method to create a new object with a specified prototype or by assigning a constructor function’s prototype property before creating new instances with the new keyword.
Example: var childObject = Object.create(parentObject);
What is the role of the this keyword within methods in JavaScript?
The this keyword within a method refers to the object on which the method was invoked. It allows methods to access and manipulate the object’s properties and other methods.
How do you add a method to a prototype in JavaScript?