Well the beauty of the links with the anchors is that the page can still function without javascript.
As for how they link the javascript with the anchors...
JavaScript can see all of the HTML that has loaded before the JS runs. (In jQuery, we ensure that the JS waits for the right moment by listening for the ready event.
The browser provides tools to identify and manipulate the HTML code, and libraries like jQuery package those tools in a convenient and standardized form.
So, to link JS with those anchors we can do things like:
$('a[href="#home"]').css ('color', 'red');
Or:
$('a[href="#work"]').click ( function () {
alert ("Still workin', boss!");
} );
See what it looks like in action at jsFiddle.
Here, we don't really need ids, because the href, anchor values are unique and descriptive. By omitting id's the code is a little cleaner, and the developer doesn't have to maintain a correlation between: anchors, hrefs, and id's.