FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses Web Development Basics

CSE

Progress0 / 6 lessons
  1. 1. How a web page reaches your screen
  2. 2. HTML structure and semantic tags
  3. 3. CSS: the box model, flexbox, and why layouts break
  4. 4. JavaScript: variables, functions and the DOM
  5. 5. Events and forms
  6. 6. fetch and working with JSON from an API

Courses › Web Development Basics

JavaScript: variables, functions and the DOM

The language of the browser, and how it reaches into your page and edits it.

13 min read · Lesson 4 of 6 · Pro

Why JavaScript exists

HTML gives structure. CSS gives looks. Neither can react. Nothing can change after the page loads. JavaScript is the third piece: it runs inside the browser and can read and change the page while the user is on it.

Add it just before the closing </body> tag:

Code
  <script src="app.js"></script>
</body>

Why at the bottom? Because the script runs the moment the browser reaches it. If it runs before the elements exist, it finds nothing.

Variables

JavaScript
let count = 0;          // can be reassigned
const name = "Ravi";    // cannot be reassigned
count = count + 1;
The rest of this lesson is Pro

The free lessons of Web Development Basics finish what they start — read those first if you have not. This one goes further, and it is part of the paid half.

A pass opens the paid lessons of every course, the mock test papers and the company-wise series. It ends on its own date; nothing renews by itself.

Get a pass — from ₹29 for 7 days

Already bought one? Log in.