Part 3- A Smarter Way to Learn JavaScript Flashcards
What are the rules for naming an array?
array names have the same naming conventions as other variables
What types of data can an array hold?
Same as any other variable: strings, numbers, variables
Can you mix data types in the same array?
Yes.
Which punctuation is used in an array?
*the list of elements has square brackets: [],
*you separate elements in the list with a comma and a space
*in an array of strings, the comma between elements goes AFTER the quotation mark.
In an array, what’s another name for a value?
an element
How do you formally refer to a specific element in an array?
The array’s name
followed by the index number inside of straight brackets
For example, cities[5] would be how you refer to the sixth element in an array called CITIES
What’s the keyword to add elements to the end of an array?
*push()
*arrayname.push(elements);
*Think of it as “push parentheses”
What’s the keyword to remove the last element of an array?
pop();
arrayname.pop();
Think of it as “pop parentheses”
Do you have to add all elements to an array in order?
No.
What happens if you call an element and it hasn’t been assigned?
It will return “undefined.”
What are the six keywords used to change the elements in an array?
pop()
push()
shift()
unshift()
splice()
slice()
*Each of these methods RETURNS a value. When we get to the W3Schools tutorial, I’ll learn which value each returns
What do pop() and shift() have in common?
They both remove elements from an array
What do push() and unshift() have in common?
They both add elements to an array
What do pop() and push() have in common?
They both work at the end of an array
What do shift() and unshift() have in common?
They both work at the beginning of an array
What do splice() and slice() have in common?
They both work in the middle of an array
How is slice() different from pop(), push(), shift(), unshift(), and splice()?
It does not affect the existing array/string (usually)
It creates a new array/string (usually)
(Technically, you could splice from the existing array BACK TO the existing array, but it would remove all the non-sliced elements from the existing array)
The methods slice() and splice() both use two numbers in the parentheses. What do they mean?
*For both slice() and splice(), the first number in parentheses is the index number where the work starts.
*for slice(), the second number is the index number AFTER the final element to be removed.
*for splice(), the second number is the total number of elements being removed.
What’s a colloquial way to think of the ELSE IF command?
“If that’s not true, check this:”
or
“If that doesn’t match, try this:”
What is this code?
for (var 1 = 0; i<=4; i++) {
//code to run goes here
}
a FOR loop