Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
115 Cards in this Set
- Front
- Back
- 3rd side (hint)
Name the five JavaScript primitives |
Numbers |
|
|
Everything that isn't a primitive is an __________.
|
Object |
|
|
Numbers, strings and booleans are object-like but are _______________.
|
Immutable. |
|
|
An object is a container of properties, which consist of __________ and ___________. |
A name and a value (and a value can be another object). |
|
|
Names of properties can be any string, including ___________. |
The empty string ''
|
|
|
Object literals, using syntax: |
Object |
|
|
Values can be retrieved in two ways:
|
Using [ ] or the dot notation. |
|
|
When an attempt is made to retrieve a nonexistent member, a value of _________ is produced. |
Undefined
|
|
|
To fill in default values use the || operator as follows:
|
var middle = stooge["middle-name"] || "none" |
|
|
To avoid a TypeError exception from trying to retrieve values from nonexistent properties, use the && operator as follows: |
flight.equipment && flight.equipment.model |
|
|
A value in an object can by updated--or added--by ___________________. |
Assignment |
|
|
Objects are passed around by _____________. They are never copied. |
Reference
|
|
|
Every object is linked to at least one prototype object from which it can ______________________. |
Inherit properties
|
|
|
The prototype link has no effect on ___________. When we make changes to an object, the object's prototype is not touched. |
Updating
|
|
|
The prototype link is used only in __________. If we try to retrieve a property that the object lacks, JavaScript attempts to retrieve it from the prototype, repeating up the chain as needed. |
Retrieval
|
|
|
Prototype relationships are _______. If we add a new property to a prototype, the property will immediately be visible to all objects based on that prototype. |
Dynamic
|
|
|
For reflection, using the ___________ operator can be helpful in determining the type of a given property. |
typeof
Returns number, string, object, undefined, Boolean. (And null?) |
|
|
The _________________ method can determine if an object has a given property in and of itself and not from elsewhere on the prototype chain
|
hasOwnProperty |
flight.hasOwnProperty(c'constructor'). //false |
|
The for in statement can loop over all of the _________ _______ in an object--including ones that are ___________. |
Property names
Inherited |
|
|
There is no guarantee on the order of the property names in a ______ __ statement.
|
for in
|
|
|
To enumerate through properties in a certain order, first create a(n) ________ of the property names and then use an incremental _____ ________.
|
Array |
|
|
The delete operator can remove a property from the object, but not from the ___________ _____________. |
Prototype linkage
|
|
|
To minimize use of global variables, create a single global variable in which to "wrap" your _________ ___________.
|
Entire Application |
|
|
Functions enclose a set of statements and are used for code reuse, information hiding and composition. They define the _________ of objects. |
Behavior |
|
|
In JavaScript, functions are objects, and can be created using a __________ ___________. |
function literal. Eg, return a + b; } ;
- OR -
var x = function optionalName(a,b){ return a+b; }; |
|
|
The four parts of a function literal are: |
1) the reserved word function 2) (optional) the function name 3) the set of parameters, wrapped in parentheses 4) a set of statements wrapped in curly braces. These are the body of the function
|
|
|
Invoking a function _________ the execution of the current function, passing control and parameters to the new function. |
suspends |
|
|
In addition to the declared parameters, every function receives two additional parameters: _______ and _______. |
this and arguments |
|
|
The this parameter is important to OOP, and its value is determined by the _____________ ____________.
|
invocation pattern |
|
|
There are four patterns of invocation in JavaScript: |
The method invocation pattern
The function invocation pattern
The constructor invocation pattern
The apply invocation pattern
They differ in how the bonus parameter this is initialized |
|
|
When a function is stored as a property of an object, we call it a ________. |
method |
|
|
Methods are members of an object. In method invocation, the this object is bound to the _____________ _________. |
containing object
Eg, var myObject = { value: 0; increment: function(inc) { this.value +=1; }
|
|
|
Methods that get their object context from this are called ______ _______. |
public methods |
|
|
When a function is not the property of an object, then it is invoked as a function, and its this is bound to the _______ object. |
global
(this feature is considered a mistake in the language design. A consequence is that a method cannot employ an inner function to help it due its work. There are workarounds, however.) |
|
|
A workaround to the global binding of functions is to pass the proper context to an inner function by specifying correct ________. |
Parameters. Eg. (that.value1, that.value2), where "that" is defined as the previous this. |
|
|
JavaScript is a ________ inheritance language |
Prototypal. This means objects can inherit directly from other objects. The language is class-free. |
|
|
Despite being prototypal, JavaScript provides a ____________ pattern, reminiscent of classical languages. |
Constructor.
Eg, |
|
|
Functions that are intended to be used with the _____ keyword are called constructors. |
new |
|
|
By convention, constructor functions are kept in variables with a ____________ name |
Capitalized.
|
|
|
Use of conventional constructor functions is _____ _____________. |
Not recommended |
|
|
Because JavaScript is a functional object-oriented language, functions can have _________ |
methods |
|
|
The __________ method lets us construct an array of arguments to use to invoke a function |
apply
eg, var array = [3, 4]; var sum = add.apply(null, array);
|
|
|
The __________ array is a bonus parameter that is available to functions when they are invoked |
arguments
This makes it possible to write functions that take an unspecified number of parameters. Use this cautiously, however. |
|
|
The _______ statement can be used to cause a function to return early (ie, instead of reaching the end of the statement block.) |
return |
|
|
A function always returns a value. If the return value is not specified, then ___________ is returned. |
undefined |
|
|
For handling ___________, JavaScript uses a try/catch mechanism similar to Java's, although with only one catch block. |
Exceptions |
|
|
JavaScript allows the basic types of the language to be ___________. |
Augmented.
Eg, Function.prototype.method = function(name, func){ this.prototype[name]=func; return this; }; |
|
|
A ____________ function is a function that calls itself, either directly or indirectly. |
recursive |
|
|
Scope in a programming language controls the _________ and ___________ of variables and paremeters |
Visibility, Longevity |
|
|
JavaScript does not have block scope, even though its syntax suggests that it does. Instead it has ________ scope. |
Function |
|
|
Because of having function scope, it's recommended in JavaScript to declare all variables at the ____ of the function body, instead of where they are first used. |
top |
|
|
Each time an enclosed function is called, a new ________ is created. |
scope |
|
|
A closure is an expression--typically a function--that can have free variables together with an environment that ____those variables. |
binds |
|
|
A closure can be 1) The ____________ for a function, kept alive after the function has returned, or 2) A stackframe which is ____ _________ after the function returns. |
Not deallocated |
|
|
Callbacks are functions that are specified to be executed after a given function is finished. They are often used for ___________ processing |
asynchronous |
|
|
A module is a function or object that presents an interface but hides its state and implementation. It can eliminate the use of ____________. |
globals |
|
|
Cascading |
calling many methods (usually setters) on a single statement.
eg, getElement(x).move(a,b).height(14).color(red); |
|
|
The practice of remembering (caching) the results of previous costly operations for quick retrieval later. |
Memoization |
|
|
JavaScript, being loosely typed, never performs _________ |
casts |
|
|
By convention, only __________ functions begin with a capital letter. |
constructor
(this avoids confusion and variable clobbering) |
|
|
__________ _________ can be used to construct an object when you don't remember the ________ __ ________. |
order of parameters |
|
|
JavaScript is conflicted about its ________nature. |
prototypal
Its prototype mechanism is obsucred by complicated syntax that looks vaguely classical. |
|
|
When a function object is created, the Function constructor runs code like this in the background: |
this.prototype = {constructor: this}; |
|
|
Every function get a _________ object, because the language doesn't provide a way to determine which functions are to be used as _______________. |
prototype constructors |
|
|
With a purely prototypal pattern, we dispense with _______ and focus instead on ____________. |
classes objects |
|
|
__________ inheritance means customizing a new object by specifying its differences from the object on which it's based. |
Differential |
|
|
By being loosely typed, JavaScript has the benefit of being unconcerned about the lineage of classes. What matters is the object's _________. |
contents |
|
|
A true array is a _________ _______of memory in which elements are access by integers. |
linear allocation |
|
|
JavaScript "arrays" are merely objects with ____________ characteristics and ___________ methods. |
array-like built-in |
|
|
Arrays created with brackets inherit from ________________. They also inherit a __________ property. |
Array.prototype length |
|
|
With JavaScript arrays, the length can be _____________ augmented or reduced. |
dynamically |
|
|
Arrays created with curly braces inherit from _______________ |
Object.prototype |
|
|
The _________ operator can remove elements from an array. The value changes to _____________. |
delete undefined |
|
|
Array.splice() removes items from an array and adjusts the __________. |
indices |
|
|
Enumeration in JavaScript is generally best handled using the conventional ____ _____ and not the for in structure. |
for loop |
|
|
By adding a function to ________, every array inherits it. |
Array.prototype |
|
|
JavaScript borrows its Regular Expression features from ______. |
Perl |
|
|
The methods that work with JavaScript regular expressions are: regexp.test string.match string.replace, __________ and ____________. |
string.search string.split |
|
|
In JavaScript, regular expressions must be entered on a _________ _____. |
single line |
|
|
The RegExp object has the following built-in properties:
|
global ignoreCase lastIndex (index at which to start) multiline source |
|
|
A RegExp class is a set of ___________. |
characters |
|
|
A RegExp factor is a character, character group, or _________ __________. |
escape sequence |
|
|
A RegExp sequence is one or more __________. |
factors |
|
|
A RegExp choice is one or more __________ |
sequences |
|
|
A regExp group can be capturing, non-capturing, positive lookahead, or __________ ___________. |
negative lookahead. |
|
|
To designate capturing, put the regexp choice in ____________. |
parentheses |
|
|
The Array.concat(item...) method makes a ____ _______ |
new array
(out of the items) |
|
|
The Array.join(separator) method makes a ___________ from an array |
String |
|
|
Array.pop() ________ and returns the last element. |
removes |
|
|
Array.push() appends items to the ____. |
end |
|
|
Array.shift() removes the _________ element and returns it. |
first |
|
|
Array.slice() makes a _________ _____ of an array |
shallow copy |
|
|
Array.sort sorts an array _________, even with numerals. |
alphabetically |
|
|
True or False: |
True |
|
|
Array.unshift() shoves items on to the _______. |
front |
|
|
The Function object has only one built-in method whose signature is ________. |
apply(thisArg, argArray).
"thisArg" specifies the object to be bound to this. |
|
|
The Number object has four built-in methods: toExponential(fractionDigits) toFixed(fractionDigits) toPrecision(precision) and ______________ |
toString(radix), where radix is the base (default 10) |
|
|
The Object object has one built-in method: |
hasOwnProperty(name) |
|
|
RegExp has two built-in methods: __________ and ___________ |
exec(String) test(String)
Test is simple and fast and returns true or false |
|
|
The String object has more than 14 _______ _______ |
built-in methods |
|
|
Since JavaScript has no linker, all compilation units are loaded into a common ________ _______. |
global object |
|
|
The values 0, NaN, '', false, null and undefined are all considered "falsy", but they are ____ ___________. |
not interchangeable |
|
|
JavaScript has a function expression as well as a function ________. |
statement |
|
|
In JavaScript you can assign a variable name to an unnamed ________.
|
function.
eg, var f = function (){ }; |
|
|
JSLint and JSHint are tools for _________ your JavaScript code |
testing |
|
|
JSON, or JavaScript Object Notation, is a lightweight _______ ________ _________. |
data interchange format. |
|
|
Always use _________ to declare variables, except when intentionally create a global. |
var |
|
|
When comparing objects, always use the ____ operator instead of the ___ operator. |
=== == |
|
|
An IIFE, or immediately invoked function expression is sometimes known as a SEAF, or _____________, |
self-executing anonymous function
|
|
|
IIFEs are variations on anonymous functions. They are wrapped in parentheses and appended with any necessary __________. |
arguments |
|
|
A closure lets you capture the value of a passed-in variable at the moment it is passed in---no matter what happens to that variable in the __________ _______. |
outer scope |
|
|
Closures are also JavaScript's way of implementing _____________. |
encapsulation |
|
|
When defining a standalone function (ie, one not bound to any object), the this variable is bound to the __________ namespace.
|
Global.
This can be circumvented conventionally by assigning the method's this variable to an intermediate that variable. |
|
|
In javaScript, objects inherit directly from _______ __________.
|
Other objects
|
|
|
JavaScript, being loosely typed, never ______.
|
Casts |
|