Chapter 4: Expressions and Operators Flashcards
(33 cards)
Object and array _______ are expressions whose value is a newly created object or array
initializers
An _____ ______ is a comma-separated list of expressions contained within square
brackets.
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
Undefined elements can be included in an array literal by simply _______ value between commas.
omitting
var sparseArray = [1,,,,5];
Object initializer expressions are like array initializer expressions, but the square brackets are replaced by ____ _____
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
Object literals can be nested
True
var rectangle = { upperLeft: { x: 2, y: 2 },
lowerRight: { x: 4, y: 5 } };
A property access expression evaluates to the value of an _____ property or an ______
element
object, array
A property access expression evaluates to the value of an object property or an array
element
expression . identifier
expression [ expression ]
If the value is not an
object (or array), it is converted to one
True
An ______ expression is JavaScript’s syntax for calling (or executing) a function or
method.
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.
An ______ _____ expression creates a new object and invokes a function (called a
constructor) to initialize the properties of that object.
object creation
Object creation expressions are
like invocation expressions except that they are prefixed with the keyword _____
new
new Object()
new Point(2,3)
JavaScript supports one ternary operator, the conditional operator ___, which combines three expressions into a single expression.
?:
The ______ operator also has side
effects: deleting a property is like (but not the same as) assigning undefined to the
property.
delete
Although _____ is one of the highest-priority operators, the _____ operation is performed on the result of the two property accesses and the function invocation.
typeof
The binary ___ operator adds numeric operands or concatenates string operands:
+
Examples of + operation for different types
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
Bitwise operators
&, |, ^, ~, «_space;(shift left),»_space; shift right with sign,»_space;> (shift right with zero fill)
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
===
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
==
The strict equality operator === evaluates its operands, and then compares the two
values as follows, performing no type conversion:
- 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
Comparison operator examples
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
The ___ operator expects a left-side operand that is or can be converted to a _____. It
expects a right-side operand that is an _____.
in, string, object
The ______ operator expects a left-side operand that is an object and a right-side
operand that identifies a class of objects
instanceof
The behavior of ___ is sometimes called “short circuiting
&&