JavaScript ECMAScript6 Flashcards
JavaScript ECMAScript6: Functions
Define Pure Function
Specific value-producing function with no side effect and doesn’t require effects from other codes.
Functions have primarily two purposes
1) Called for side effect
2) Called for return value
Recursive function
Function that calls on itself
Stack Space
When computer stacks runs out of space.
Call Stack
Place where computer stores context
Almost all JavaScript values have properties. What are the two exceptions?
Null and Undefined
Access properties in JS by __ and __
. and [ ]
ex: value.x or value[ ]
How is value.x and value[] evaluated differently?
When using a dot, the word after the dot is the literal name of the property. When using square brackets, the expression between the brackets is evaluated to get the property name. Whereas value.x fetches the property of value named “x”, value[x] tries to evaluate the expression x and uses the result, converted to a string, as the property name. The elements in an array are stored as the array’s properties, using numbers as property names. Because you can’t use the dot notation with numbers and usually want to use a binding that holds the index anyway, you have to use the bracket notation to get at them.
Two ways to call length in array of variable varx
varx.length and varx[“length”]
What does doh.toUpperCase() do?
writes it all in uppercase as in DOH.
What does DOh.toLowerCase() do?
writes it all in lowercase as in doh.
Properties that contain functions is called ______?
methods
sequence = [5, 23, 67, 2]
sequence.push(4) would do what?
add 4 to the end of an array.
sequence = [5, 23, 67, 2]
sequence.pop() would do what?
remove the last item in the array
let day1 = { squirrel: false, events: ["work", "touched tree", "pizza", "running"] }; console.log(day1.squirrel); console.log(day1.wolf);
What would the logs print out?
false
undefined
Braces have two meanings in javascript? What is it?
At the start of a statement, they start a block of statements.
In any other position, they describe an object.
Reading a property that doesn’t exist will give you the value __________.
undefined
assign a value to a property expression with the = operator. This will ______ the property’s value if it already existed or _______ a new property on the object if it didn’t.
replace
create
Inside braces { } how do you separate properties within?
separate by ,
let anObject = {left: 1, right: 2};
delete anObject.left;
console.log(anObject.left);
console. log(“left” in anObject);
console. log(“right” in anObject);
What does it print out?
undefined
false
true
what does the ‘in’ operator do?
The binary in operator, when applied to a string and an object, tells you whether that object has a property with that name.