Chapter 4: Expressions and Operators Flashcards

(33 cards)

1
Q

Object and array _______ are expressions whose value is a newly created object or array

A

initializers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

An _____ ______ is a comma-separated list of expressions contained within square
brackets.

A

array initializer
[] // An empty array: no expressions inside brackets means no elements
[1+2,3+4] // A 2-element array. First element is 3, second is 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Undefined elements can be included in an array literal by simply _______ value between commas.

A

omitting
var sparseArray = [1,,,,5];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Object initializer expressions are like array initializer expressions, but the square brackets are replaced by ____ _____

A

curly brackets
var p = { x:2.3, y:-1.2 }; // An object with 2 properties
var q = {}; // An empty object with no properties
q.x = 2.3; q.y = -1.2; // Now q has the same properties as p

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Object literals can be nested

A

True
var rectangle = { upperLeft: { x: 2, y: 2 },
lowerRight: { x: 4, y: 5 } };

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A property access expression evaluates to the value of an _____ property or an ______
element

A

object, array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A property access expression evaluates to the value of an object property or an array
element

A

expression . identifier
expression [ expression ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If the value is not an
object (or array), it is converted to one

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

An ______ expression is JavaScript’s syntax for calling (or executing) a function or
method.

A

invocation
f(0) // f is the function expression; 0 is the argument expression.
Math.max(x,y,z) // Math.max is the function; x, y and z are the arguments.
a.sort() // a.sort is the function; there are no arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

An ______ _____ expression creates a new object and invokes a function (called a
constructor) to initialize the properties of that object.

A

object creation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Object creation expressions are
like invocation expressions except that they are prefixed with the keyword _____

A

new
new Object()
new Point(2,3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

JavaScript supports one ternary operator, the conditional operator ___, which combines three expressions into a single expression.

A

?:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The ______ operator also has side
effects: deleting a property is like (but not the same as) assigning undefined to the
property.

A

delete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Although _____ is one of the highest-priority operators, the _____ operation is performed on the result of the two property accesses and the function invocation.

A

typeof

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The binary ___ operator adds numeric operands or concatenates string operands:

A

+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Examples of + operation for different types

A

1 + 2 // => 3: addition
“1” + “2” // => “12”: concatenation
“1” + 2 // => “12”: concatenation after number-to-string
1 + {} // => “1[object Object]”: concatenation after object-to-string
true + true // => 2: addition after boolean-to-number

17
Q

Bitwise operators

A

&, |, ^, ~, &laquo_space;(shift left),&raquo_space; shift right with sign,&raquo_space;> (shift right with zero fill)

18
Q

The ____ operator is
known as the strict equality operator (or sometimes the identity operator), and it checks
whether its two operands are “identical” using a strict definition of sameness

19
Q

The ____
operator is known as the equality operator; it checks whether its two operands are
“equal” using a more relaxed definition of sameness that allows type conversions

20
Q

The strict equality operator === evaluates its operands, and then compares the two
values as follows, performing no type conversion:

A
  • If the two values have different types, they are not equal.
  • If both values are null or both values are undefined, they are equal.
  • If both values are the boolean value true or both are the boolean value false, they
    are equal
21
Q

Comparison operator examples

A

1 + 2 // Addition. Result is 3.
“1” + “2” // Concatenation. Result is “12”.
“1” + 2 // Concatenation. 2 is converted to “2”. Result is “12”.
11 < 3 // Numeric comparison. Result is false.
“11” < “3” // String comparison. Result is true.
“11” < 3 // Numeric comparison. “11” converted to 11. Result is false.
“one” < 3 // Numeric comparison. “one” converted to NaN. Result is false

22
Q

The ___ operator expects a left-side operand that is or can be converted to a _____. It
expects a right-side operand that is an _____.

A

in, string, object

23
Q

The ______ operator expects a left-side operand that is an object and a right-side
operand that identifies a class of objects

24
Q

The behavior of ___ is sometimes called “short circuiting

25
JavaScript uses the ___ operator to assign a value to a variable or property
=
26
a <<= b
a = a << b
27
&= a &= b
a = a & b
28
Like many interpreted languages, JavaScript has the ability to interpret strings of JavaScript source code, evaluating them to produce a value. JavaScript does this with the global function _____
eval() eval("3+2") // => 5
29
x > 0 ? x : -x
// The absolute value of x
30
?:
The operands of the conditional operator may be of any type. The first operand is evaluated and interpreted as a boolean. If the value of the first operand is truthy, then the second operand is evaluated, and its value is returned. Otherwise, if the first operand is falsy, then the third operand is evaluated and its value is returned.
31
For ?: operator, Only one of the second and third operands is evaluated, never both
true
32
______ is a unary operator that attempts to delete the object property or array element specified as its operand
delete
33
The ______ operator is a binary operator whose operands may be of any type. It evaluates its left operand, evaluates its right operand, and then returns the value of the right operand
comma