Chap. 4 eloquent javascript Flashcards
let listOfNumbers = [2, 3, 5, 7, 11];
console.log(listOfNumbers[2]);
console. log(listOfNumbers[0]);
console. log(listOfNumbers[2 - 1]);
// → 5 // → 2 // → 3
Almost all JavaScript values have properties. The exceptions are______ and________.
null
undefined
true or false?
null has properties
false
The two main ways to access properties in JavaScript are with a _________ and with ____________.
dot notation
square brackets
null.length;
returns?
// → TypeError: null has no properties
Write in bracket notation
array.length
array[‘length’]
Write in dot notation
array[‘length’]
array.length
let doh = "Doh"; console.log(typeof doh.toUpperCase);
// → function
let doh = "Doh"; console.log(doh.toUpperCase());
// → DOH
let sequence = [1, 2, 3];
sequence. push(4);
sequence. push(5);
console. log(sequence);
// → [1, 2, 3, 4, 5]
let sequence = [1, 2, 3, 4, 5];
console.log(sequence.pop());
console.log(sequence);
// →5
// → [1, 2, 3, 4]
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);
// → false // → undefined // → false
Properties in objects whose names aren’t valid binding names or valid numbers have to be_________.
quoted
let anObject = {left: 1, right: 2}; console.log(anObject.left); // → delete anObject.left;
console.log(“left” in anObject);
// →
console.log(“right” in anObject);
// →
// → 1
// → false // → true
To find out what properties an object has, you can use the ___________ function
Object.keys
console.log(Object.keys({x: 0, y: 0, z: 2})); // →
// → [“x”, “y”, “z”]
There’s an ___________ function that copies all properties from one object into another.
Object.assign
let object1 = {value: 10}; let object2 = object1; let object3 = {value: 10};
console.log(object1 == object2);
// →
console.log(object1 == object3);
// →
// → true
// → false
let object1 = {value: 10}; let object2 = object1; let object3 = {value: 10}; object1.value = 15;
console.log(object2.value);
// →
console.log(object3.value);
// →
// → 15 // → 10
The _________ method returns the first index at which a given element can be found in the array, or -1 if it is not present.
indexOf()
The indexOf() method returns the first index at which a given element can be found in the array, or _____ if it is not present.
-1
The ____________ method returns the last index at which a given element can be found in the array, or -1 if it is not present.
lastIndexOf()
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.
Slice()
let kim = "Kim"; kim.age = 88; console.log(kim.age); // →
// → undefined
The __________ method returns the first index at which a given element can be found in the array, or -1 if it is not present.
indexOf()
console.log("one two three".indexOf("ee")); // →
// → 11
The ________ method removes whitespace (spaces, newlines, tabs, and similar characters) from the start and end of a string.
trim
let anObject = {left: 1, right: 2};
console.log(anObject.left); // →
// → 1
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.
split()
let sentence = "Secretarybirds specialize in stomping"; let words = sentence.split(" "); console.log(words);
returns?
// → [“Secretarybirds”, “specialize”, “in”, “stomping”]
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.
join()
You can use a similar _________ notation to call a function with an array of arguments
three-dot