Chap. 4 eloquent javascript Flashcards

1
Q

let listOfNumbers = [2, 3, 5, 7, 11];
console.log(listOfNumbers[2]);

console. log(listOfNumbers[0]);
console. log(listOfNumbers[2 - 1]);

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

Almost all JavaScript values have properties. The exceptions are______ and________.

A

null

undefined

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

true or false?

null has properties

A

false

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

The two main ways to access properties in JavaScript are with a _________ and with ____________.

A

dot notation

square brackets

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

null.length;

returns?

A

// → TypeError: null has no properties

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

Write in bracket notation

array.length

A

array[‘length’]

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

Write in dot notation

array[‘length’]

A

array.length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
let doh = "Doh";
console.log(typeof doh.toUpperCase);
A

// → function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
let doh = "Doh";
console.log(doh.toUpperCase());
A

// → DOH

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

let sequence = [1, 2, 3];

sequence. push(4);
sequence. push(5);
console. log(sequence);

A

// → [1, 2, 3, 4, 5]

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

let sequence = [1, 2, 3, 4, 5];
console.log(sequence.pop());

console.log(sequence);

A

// →5

// → [1, 2, 3, 4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
let day1 = {
  squirrel: false,
  events: ["work", "touched tree", "pizza", "running"]
};

console. log(day1.squirrel);
console. log(day1.wolf);

day1. wolf = false;
console. log(day1.wolf);

A
// → false
// → undefined
// → false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Properties in objects whose names aren’t valid binding names or valid numbers have to be_________.

A

quoted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
let anObject = {left: 1, right: 2};
console.log(anObject.left);
// → 
delete anObject.left;

console.log(“left” in anObject);
// →
console.log(“right” in anObject);
// →

A

// → 1

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

To find out what properties an object has, you can use the ___________ function

A

Object.keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
console.log(Object.keys({x: 0, y: 0, z: 2}));
// →
A

// → [“x”, “y”, “z”]

17
Q

There’s an ___________ function that copies all properties from one object into another.

A

Object.assign

18
Q
let object1 = {value: 10};
let object2 = object1;
let object3 = {value: 10};

console.log(object1 == object2);
// →
console.log(object1 == object3);
// →

A

// → true

// → false

19
Q
let object1 = {value: 10};
let object2 = object1;
let object3 = {value: 10};
object1.value = 15;

console.log(object2.value);
// →
console.log(object3.value);
// →

A
// → 15
// → 10
20
Q

The _________ method returns the first index at which a given element can be found in the array, or -1 if it is not present.

A

indexOf()

21
Q

The indexOf() method returns the first index at which a given element can be found in the array, or _____ if it is not present.

A

-1

22
Q

The ____________ method returns the last index at which a given element can be found in the array, or -1 if it is not present.

A

lastIndexOf()

23
Q

The________ method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified.

A

Slice()

24
Q
let kim = "Kim";
kim.age = 88;
console.log(kim.age);
// →
A

// → undefined

25
Q

The __________ method returns the first index at which a given element can be found in the array, or -1 if it is not present.

A

indexOf()

26
Q
console.log("one two three".indexOf("ee"));
// →
A

// → 11

27
Q

The ________ method removes whitespace (spaces, newlines, tabs, and similar characters) from the start and end of a string.

A

trim

28
Q

let anObject = {left: 1, right: 2};

console.log(anObject.left);
// →
A

// → 1

29
Q

The _________method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.

A

split()

30
Q
let sentence = "Secretarybirds specialize in stomping";
let words = sentence.split(" ");
console.log(words);

returns?

A

// → [“Secretarybirds”, “specialize”, “in”, “stomping”]

31
Q

The _______ method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string.

A

join()

32
Q

You can use a similar _________ notation to call a function with an array of arguments

A

three-dot