w5d5/w6d1 - javascript Flashcards
What are the falsy values in JS?
-1 0 "" undefined NaN false
Does JS have implicit return?
no
What are the 5 JS primitives?
integer string boolean undefined null
How does var scoping/reassignment work?
available within the function it is defined in
can be reassigned
How does let scoping/reassignment work?
block scoped
can be reassigned
How does const scoping/reassignment work?
block scoped
cannot be reassigned
Can you use a variable before it is defined?
Yes.
It must be defined in the same scope.
This only works for var/let. Does not work for const.
What’s the story with constructor functions?
ProudCamelCased
sort of like declaring a class
What are the different types of function invocation?
method-style: the current ‘this’ will be the enclosing scope.
constructor-style: ‘this’ will be enclosed by the constructor method
What does ‘this’ refer to?
The current context.
Roughly equivalent to ruby’s self.
How do you get a function in JS to implicitly return?
Make it a one-line fat-arrow function.
How does string interpolation work
backticks for quotes
${ … } to interpolate …
Fat arrow functions are like lambdas in which way?
They return execution to the context in which they are defined.
What happens if you send extra params to a method?
They are unused.
How do you access all arguments passed to a function?
They can be accessed via the ‘arguments’ array-like object available within the method
How do you treat arguments like an array?
arguments_as_an_actual_array = Array.prototype.slice.call(arguments)
OR (ES6)
Array.from(arguments)
With function-style invocation, what is ‘this’ set to?
window
With method-style invocation, what is ‘this’ set to?
the object that we call the method on
With constructor-style invocation, what happens behind the scenes? What is ‘this’ set to?
a new, empty object is created.
the object’s __proto__ property is set to Classname.prototype
the Classname function is set with ‘this’ set to the blank object.
Where is apply defined, what does it take as parameters and what does it do?
Function.prototype.apply
it takes an object to bind ‘this’ to, and it takes an array of arguments to be passed to the method it is being called on