HTML and CSS Reference
In-Depth Information
window.addEventListener('keydown', onKeyboardEvent, false);
};
</script>
</body>
</html>
You can see this example—like the previous example, 07-key-codes.html —prints the same messages
to the console, but, because we're now using key names instead of key codes , our switch statement is
easier to understand. Not only is it clearer, but it prevents you from accidentally typing a wrong number.
We won't use the keycode.js file in this topic because the exercises are relatively simple and I want you
to see exactly what's going on in the examples. But it can make your code more readable, so in more
complex programs it's something you should consider using.
Summary
This chapter covered just about all the JavaScript basics you need to understand the rest of the examples
found in this topic. You now know about setting up an HTML5 document, debugging, loops, events, and
handlers. We've touched on JavaScript objects, basic user interaction, and created a few utility functions
to make things a little easier. That's a lot of material! Don't worry if some of these areas are still a little
vague. Most of the topics here are shown in more detail as we get into specific techniques, and you can
always come back here to brush up on the basics. At the very least, now you are familiar with the terms
and concepts, and you're ready to move forward.
 
Search WWH ::




Custom Search