● Variables provide useful data. The example above asks users to enter their names then stores that information in a variable called name.
● In programming, a string is a snippet of text. To create the complete text label, we join the string “Player 10: ” to the name variable, e.g. “Player 10: Matt”.
● An event occurring on a website triggers code to run. The code that updates the label is run when a click event is triggered by our example above which detects when the button is clicked.
A programming API provides programmers with ready-made codes that can be used to build programs that would otherwise be difficult or impossible to design. As with ready-made furniture kits for home building, programming kits do the same thing.
The process of building a bookshelf is much simpler if you just screw together ready-made panels, rather than going out to find the right wood, cutting all the panels to the right shape and size, and finding the correct-sized screws, and attaching them to each other.
Generally, they can be divided into two groups.
Your web browser has APIs embedded into it to expose data from the computer environment, or to perform complex tasks. For example:
● Document Object Model (DOM) API allows you to create, remove, and edit HTML, apply dynamic styles to your page, etc., using HTML and CSS. It’s the DOM that displays new content (as we saw in our example above) whenever you see a popup window appear on a page.
● Geographic information can be retrieved by the Geolocation API. Your location is plotted on Google Maps using this method.
● 2D and 3D animated graphics can be created using Canvas and WebGL APIs. See Chrome Experiments and webglsamples for some amazing examples of what’s possible using these web technologies.
● APIs like HTMLMediaElement and WebRTC make multimedia playable right inside of web pages, allowing you to do interesting things with multimedia on the web. You can display a snapshot taken by your camera on someone else’s computer (see our simple Snapshot demo for more information).
The default browser does not include third-party APIs, and you must usually download their code and information from the Web. Examples include:
● The Twitter API makes it possible to display tweets from your website.
● OpenStreetMap API and Google Maps API offer various capabilities for embedding custom maps into your website.