iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

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

HTML structure CSS presentation JS behaviour
Fig 1. HTML structures the page, CSS styles it, JavaScript makes it interactive.

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!');

Test yourself

Q1. JavaScript runs primarily in…
Q2. HTML and JavaScript split duties as…
Q3. Where should app `<script>` tags typically go?

Discussion

Loading…