JS Introduction
JavaScript is the programming language of the web. It runs in every browser, on servers (Node.js), in mobile apps, and even on hardware. It's the single most-used language in the world.
What JavaScript can do
- Read & change the HTML on the page (the DOM).
- React to clicks, typing, scrolling, and other events.
- Send and receive data over the network (
fetch). - Animate things in real time.
- Store data on the device (localStorage, IndexedDB).
- Run heavy work off the main thread (Web Workers).
Where it fits
Running JavaScript on a page
HTML
<!DOCTYPE html>
<html>
<body>
<p id="hello"></p>
<script>
document.getElementById("hello").textContent = "Hello, JavaScript!";
</script>
</body>
</html>
Tip: JavaScript runs top-to-bottom and pauses page rendering. Put
<script> tags at the end of <body>, or use defer in the head, so users see content before scripts load.Example
Example
<!DOCTYPE html>
<html>
<body>
<p id="out"></p>
<script>
document.getElementById("out").textContent = "Hello from JS Introduction!";
</script>
</body>
</html>
Try it Yourself »
Exercise
Print a greeting to the browser console.
.log('Hello, JavaScript!');
The global object that lets you log to dev tools.
Discussion
Loading…