Good question. In about a week, we'll be creating functions, often anonymous ones, to hand to the browser to be invoked by the browser when events occur. These functions will be handed to the browser by having them be the arguments of functions defined by the browser (or by a helper library).
Both.
A function can be the value of another function. The
function f
can return a function g
(or an
anonymous function with the same behavior).
A function can also be the argument of another function. A function h
can take a function as its argument. Maybe the g
that was returned by f
A function is an object that can be return and passed, like numbers, strings, dictionaries, etc.
Yes, anonymous function can be values.
This is an important idea in web development. See the first question.
Yes. In fact, later in the course, we will talk about "callback hell," which happens when you have many layers like that. Fortunately, there were innovations that greatly reduced callback hell.
Not appreciably. I prefer Firefox, and I encourage you to use it, but....
They are quite similar, but different.
map
collects
and returns an array of the values;
forEach
doesn't
return anything.
So, map is more like a list comprehension, while forEach is like a for
loop.
Multidimensional arrays are often represented as nested arrays, in which case, yes, you can map
across any dimension.
dictionaries aren't sequences, but their keys are, so we often use forEach
and map
on the keys of a dictionary:
Note the use of the square bracket notation. Can't use "." there
I'm not sure why you'd want to. Why have the array w/o an index?
You an use the three-arg version and just ignore the second arg:
Either is fine.
let
and var
are storage locations that are read/write. const
is a storage location that is read-only
"In hell, variables don't and constants aren't".
Both let
and var
are fine.
All the JS files go into one namespace bucket, unless we use the new module system, which we won't. For now.
No; functions can be declared with const
. In fact, they probably should be.
On the server, you can use any language you want, including JavaScript
In the browser, you can use any language you want, as long as its JavaScript
It is a serious, industrial strength language, running in the browser.
Yes, all changes are local to the browser tab, and disappear when the browser is refreshed.
For long-term persistence, we need a back-end database. We'll learn how to do that.
We will!
Arrow functions are a shorthand for the longer syntax. They have some subtle differences that won't affect us.
I'll demo alert
NaN
is "Not a Number" — a special object used when calculations go awry.
null
is like Python None
and Java's and C's null