Technology • Updated 8 November 2026

JavaScript for Beginners: Core Concepts, ES6 Features and a First Project, With Examples

Learn JavaScript basics: variables, data types, functions, arrays, objects, the DOM, events, ES6 features like arrow functions and template literals, async code and a small project to practise.

JavaScriptES6DOMweb developmentbeginners
⏱ 5 min read

JavaScript is the language of the web. It makes pages interactive, runs in every browser and, with Node.js, powers servers too. It is often the first programming language people learn for web development jobs in India. This guide covers the core ideas, the modern ES6 features you will use daily and a first project to cement them.

Where JavaScript runs

Every modern browser has a JavaScript engine. You can try code right now in your browser's developer console (press F12), or add it to a web page with a script tag. For learning, you only need a browser and a text editor such as VS Code.

Variables and data types

Use const for values that will not be reassigned, and let for values that will change. Avoid var in new code.

const name = "Asha";
let age = 24;
const skills = ["HTML", "CSS", "JS"];
const user = { name, age, active: true };

The main types are string, number, boolean, null, undefined, object (including arrays) and symbol, plus BigInt. Use typeof to check the type of a value, and remember that == converts types while === compares strictly. Prefer ===.

Functions

function add(a, b) { return a + b; }
const multiply = (a, b) => a * b;      // arrow function
const greet = (name = "friend") => `Hello, ${name}!`;

Arrow functions give shorter syntax, and template literals (with backticks) let you embed values in strings. Default parameters, shown above, avoid undefined arguments.

Arrays and objects

Arrays hold ordered lists, and objects hold key-value pairs. The most useful array methods are map, filter, reduce, find and forEach.

const prices = [100, 250, 400];
const withGST = prices.map(p => p * 1.18);
const expensive = prices.filter(p => p > 200);
const total = prices.reduce((sum, p) => sum + p, 0);

Use destructuring and the spread operator to work with data neatly:

const [first, ...rest] = prices;
const { name, age } = user;
const updated = { ...user, age: 25 };

Control flow

  • if / else and switch make decisions.
  • for, for...of and while loops repeat actions.
  • The optional chaining operator user?.address?.city avoids errors when something is missing, and ?? provides defaults for null or undefined values.

The DOM and events

The Document Object Model represents the page as a tree you can change with JavaScript.

const btn = document.querySelector("#calc");
const out = document.querySelector("#result");
btn.addEventListener("click", () => {
  const a = Number(document.querySelector("#a").value);
  const b = Number(document.querySelector("#b").value);
  out.textContent = a + b;
});

Always convert input values to numbers when needed, since input values are strings. Validate inputs and show helpful errors. You can see this pattern at work in any calculator on this site, such as the percentage calculator.

Asynchronous JavaScript

Some tasks take time, such as fetching data. Promises and async/await let you write such code clearly.

async function loadUsers() {
  try {
    const res = await fetch("https://example.com/api/users");
    if (!res.ok) throw new Error("Request failed");
    const data = await res.json();
    console.log(data);
  } catch (err) {
    console.error(err.message);
  }
}

Modules and tools

Modern code is split into modules using import and export. Package managers like npm let you install libraries. Browsers include debugging tools, so learn to use the console, the sources tab and the network tab. See Node.js for beginners and React hooks for the next steps.

A first project: tip splitter

  1. Create an HTML form with bill amount, tip percentage and number of people.
  2. Write a function that calculates the tip and per-person amount.
  3. Attach it to the button's click event, and show the result.
  4. Validate empty or negative input.
  5. Style it with CSS and make it mobile friendly.

Compare yours with our tip split calculator.

Common beginner mistakes

  • Forgetting that input values are strings.
  • Using == and being surprised by coercion.
  • Not handling errors from network calls.
  • Modifying the DOM inside long loops, which is slow.
  • Copying code without understanding it. Practise by rewriting examples from memory.

How to keep learning

Build small projects weekly: a to-do list, a quiz, a weather widget, an EMI calculator. Read others' code, learn browser dev tools and practise problems. After JavaScript, learn a framework and testing. Consistent practice for three to six months can make you job-ready for junior roles.

Practice ideas for the first month

Week 1: variables, types and functions, with small console exercises. Week 2: arrays and objects, with a program to filter and total a shopping list. Week 3: the DOM, building a tip splitter and a unit converter. Week 4: fetch data from a public API and display it, handling loading and error states. Keep every project in a Git repository on GitHub, write a short README for each and refactor your earlier code as you learn. Recruiters value a handful of working, well-explained projects far more than a long list of tutorial certificates.

Frequently asked questions

Is JavaScript hard for beginners?

It has quirks, but the basics are approachable with regular practice.

Should I learn ES6?

Yes. let, const, arrow functions, template literals and destructuring are standard in modern code.

What is the difference between == and ===?

== converts types before comparing, while === compares values and types strictly.

What do I need to start?

A browser and a code editor such as VS Code.

How long will it take to learn?

Basics in a few weeks, job readiness often takes several months of project practice.

Is JavaScript the same as Java?

No. They are different languages.

Last reviewed 8 November 2026. Rates, limits and rules change, so confirm figures with the official source before you act.

Free tools related to this article

Keep reading

Information on AMTools is for general guidance and is not professional financial, tax, legal or medical advice. Rules, rates and limits change, so check the latest official source before acting.