Week 2 Test Flashcards
what is the format to write a fat arrow function
const functionName = (parameters, go, here) => {
statement1;
statement2;
return <a>;
}</a>
If you have a singular parameter and you’re writing a fat arrow function, what is special about that?
you don’t have to include the parentheses around the variable
if you don’t have any parameters and you’re writing a fat arrow function, what must you do?
you still have to include empty parentheses where the parameters would have gone
demonstrate the format for writing a function with the fat arrow syntax in a single line of code
const functionName = argument => expression;
what is the real benefit from writing code in a singular line using the fat arrow function
you can do implicit returns
when can’t you do an implicit return in a fat arrow function
when the fat arrow uses multiple statments
if you have empty curly brackets immediately after a fat arrow, what does JavaScript evaluate that as?
an empty block
what is the default value of an empty block
undefined
what must you do if you want a single expression fat arrow to return an object?
wrap the curly brackets in parentheses
what is an object
a data structure that stores other data
what are the two main differences between objects and arrays
- arrays are indexed with numbers and objects are index using keys
- order is not guaranteed in an object
what are POJOs?
plain old javascript objects
write a code to assign the value of blue to the key of color to the object of car using bracket notation
> car[“color”] = “Blue”;
what is the preferred method to determine if a key exists in an object an provide an example of this using looking for the color key in the car object
using the in operator
ex.
“color” in car
write a code to assign the value of blue to the key of color to the object of car using dot notation
car.color = “blue”
can you use variables as keys with dot notation or bracket notation?
bracket
if you try to use a variable as a key with dot notation, what will JS interpret that variable as?
it will interpret it as a string, not a variable
what is the default value when accessing a key that is not in an object?
undefined
can we use got notation to iterate through object’s values? If yes how? if no, why not?
no because we can only use variables as keys in bracket notation
What is a method?
a function that belongs to an object; every method is a function, but not every function is a method; it is just a key-value pair where the key is the function name and the value is the function definition
what does Object.keys() do?
it accepts an object as the argument and returns an array of the keys within that object
what does Object.values() do?
accepts an object as the argument and returns an array of the values within that Object
what is the return value of Object.values
an array of values
what is the return value of Object.keys
an array of keys
what does Object.entries() do?
accepts an object as the argument and returns an array of the [key, value] pairs within that Object.
what data type are keys and values normally in objects?
keys are strings, but values can be anything
can you increase the value in an object if the data type is a number
yes
in the car object, where the key of year has a value of 1927; what is the format to increase that year by one and by three?
car.year++;
car.year+= 3;