Here is a representative list of questions for the final. You should be able to answer these questions or questions very similar to them.
this
differs from other variables (e.g. local or global variables).Which of the following are valid ways of accessing the element at the entry with index 1 in an array a
?
a.1
a."1"
a1
a[1]
a["1"]
a(1)
a("1")
What happens when we call a function with more arguments than its definition suggests?
What is the result of the expression ("2" + 3)
?
"23"
23
"5"
5
NaN
("2" * 3)
and ("2" * "3")
.Which of the following values are treated as “falsy” (i.e. considered as false for the purposes of a conditional)?
0
NaN
-1
false
"false"
""
{}
null
undefined
[]
this
variable behaves for such functions.List at least 4 methods each, and describe the behavior of those methods, for each of the following object classes (you should also know the behavior of all standard methods for these classes, if given their name):
class
syntax, be able to define a small class that exhibits a certain required behavior (e.g. a counter, person or task class).Which of the following can be possible scopes for local variables declared via let
? What about variables declared via var
?
for
loopsoneTime(f)
with the following behavior. It expects as argument a function f
that would be called with no arguments. It then returns a function g
that when called (you can assume with no arguments) will call f
and return the same value that f
would return, but so that subsequent calls to g
just return that same value without calling f
again. Further, the function f
should not be called until g
is called for the first time.f
to be called at some time in the future, say in 1 second? Show the precise syntax. Provide reasons why f
might not actually be called in exactly 1 second.Outside of the Function
prototype methods like bind
, call
and apply
, there are three other ways of invoking a function:
this
object is in each case.Be able to provide the CSS selector that would represent something like (this is just one example) “all paragraph tags that are within a section tag with class ‘topic’, when we hover over them.”