For sure!
We use var
or let
or const
to declare a variable. It's global if it's declared outside the scope of any function.
In strict mode, we must declare variables before using them (assigning to them). Failing to declare throws an error.
In loose mode, assigning to an undeclared variable creates it. Which might be a mistake...
Yes
An event object is created by the browser to summarize what's going on when an event occurs. It's passed as an argument to any event handlers.
Weird, isn't it? Why use a hyperlink, and then defeat its purpose. But what we're doing is exploiting the fact that a hyperlink is clickable in a way that is accessible (all assistive technologies know that they are clickable).
Nowadays, we might prefer button
instead, but
sometimes we want a bit of both.
Yes, using the a
(hyperlink) tag is
accessible. Nowadays, so is button
. But other things are
not (div
). (Without invoking ARIA.) You should probably
use either A or BUTTON.
jQuery wraps up (packages?) the DOM objects in an object that allows us to use all the jQuery API.
Wrapped sets are the jargon for the things that jQuery returns. They aren't DOM elements directly, but are wrapped up in an object that supports the jQuery API.
one
and some
are methods from my
plug-in. They check that the wrapped set either has exactly one thing
in it, or that it is not empty. If it's empty, they will throw an
error, instead of silently doing nothing.
Great question. I need to remind myself, and I found this great SO post about properties versus attributes in HTML. In short, attributes are the things in the tags in the HTML source, and properties are their JS equivalents in the DOM. Most are the same, but value
might be different.
Of course, you might mean CSS properties.
Meaning the onclick
attribute? You could do that:
However, that's not considered best practice: (1) it mixes JS code with HTML, and they might have different authors or the HTML might have been generated from a database or something, (2) we lose the abstraction of mapping over a list of items, (3) we lose the ability to use delegated handlers, (4) we can't share the JS across multiple pages, and (5) it's just ugly.
We often find that the most convenient place to put the data we
need is right in the DOM. The data-
attributes allow us
to do that.
If we didn't have this ability, we'd have to somehow look up the values in some data structure, probably indexed by some property of the DOM element, and that brings us right back to where we started.
Only a little? That's pretty good! It took me a long time to get comfortable with them.
Closures are functions that remember the values of free variables from their original context.
Great!