Introducing Javascript
So far, we've used HTML to give our webpages content and structure, and we've used CSS give them presentation.
Next, we're going to use Javascript to add functionality and interactivity to those web pages.
A while ago, we used our browser's developer tools to write a simple Javascript program. We're going to revisit that now.
What Javascript is for
Although the web began as a way for scientists and governments to trade written documents, people quickly tried to make the web do more exciting things.
Flash was used in the early days of the web, but Flash made webpages slow and insecure, didn't work well on mobile devices and had poor accessibility.
Javascript was the first true programming language invented for the web. We can use it to build complex, interactive websites that, if done properly, avoid most of the issues with Flash.
Many popular websites, like Twitter, Facebook, BBC iPlayer and Gmail, rely heavily on Javascript.
Compared to HTML and CSS
One of the key advantages Javascript has over simpler languages like HTML and CSS is logic.
HTML and CSS give a browser a fixed recipe for what to display on the screen. That recipe is the same under all circumstances.
However, we can use Javascript to tell a browser to do things only under certain conditions.
For instance, if a user clicks a button, we could display a menu, show some extra text, or trigger an animation.
Not all those conditions have to be related to user input. We can do things depending on data coming from elsewhere, so we can update a web page in real-time without waiting for the user to reload.
Where Javascript runs
For this module, we'll focus on Javascript running in the browser - where it was originally designed to run.
In later modules, we'll look at other uses of javascript.
Part of Adding interactivity
- Introducing Javascript
- Your first Javascript program
- Variables
- Conditional logic
- Affecting the page
- Making a menu
- Responding to user actions
- Keep your Javascript accessible
- Get confident with Javascript
- Add interactivity to your prototypesP