JavaScript Basics for Beginners

    Atul Kabra3 min readUpdated

    JavaScript is the programming language of the web browser. While HTML gives a page structure and CSS gives it style, JavaScript gives it behaviour — responding to clicks, validating forms, updating content without reloading, and far more. It is the only language that runs natively in every browser, which makes it one of the most useful languages a beginner can learn.

    Variables: storing values

    A variable is a named container for a value. In modern JavaScript you declare variables with let (for values that can change) and const (for values that won't):

    // const for values that should never be reassigned
    const siteName = "Infoplanet";
    
    // let for values that will change later
    let visitorCount = 0;
    visitorCount = visitorCount + 1; // now 1
    

    Prefer const by default and only switch to let when you genuinely need to reassign. You may see older code using var — avoid it in new code, as let and const behave more predictably.

    Data types you'll use constantly

    const name = "Asha";        // string  — text
    const age = 21;             // number  — integers and decimals
    const isStudent = true;     // boolean — true or false
    const courses = ["HTML", "CSS", "JS"]; // array — an ordered list
    const user = { name: "Asha", age: 21 }; // object — named properties
    

    You read an array item by its position (starting at zero) and an object property by its name:

    console.log(courses[0]);  // "HTML"
    console.log(user.name);   // "Asha"
    

    Functions: reusable blocks of logic

    A function is a named piece of code you can run whenever you need it. The modern arrow function syntax is clean and common:

    // A function that takes a name and returns a greeting
    const greet = (name) => {
      return `Hello, ${name}!`;   // template literals use backticks and ${ }
    };
    
    console.log(greet("Asha")); // "Hello, Asha!"
    

    The ${ ... } inside backticks is a template literal — a tidy way to insert values into a string.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses

    Making decisions with conditionals

    const marks = 72;
    
    // if / else lets your code choose a path
    if (marks >= 75) {
      console.log("Distinction");
    } else if (marks >= 35) {
      console.log("Pass");
    } else {
      console.log("Needs improvement");
    }
    

    Repeating work with loops

    When you need to do something for every item in a list, a loop saves you from copying code:

    const subjects = ["HTML", "CSS", "JavaScript"];
    
    // for...of walks through each item in turn
    for (const subject of subjects) {
      console.log(`Studying ${subject}`);
    }
    

    Where JavaScript runs

    JavaScript started in the browser but now runs on servers too (through Node.js), powering everything from web pages to APIs. The fundamentals on this page are the same in both places. Once these basics are comfortable, the natural next steps are learning how JavaScript talks to the page through the DOM and how it reacts to user events.

    Common mistakes

    • Using var in new code. Stick to const and let; they have clearer, block-level scoping.
    • Confusing = with ===. A single = assigns a value; === compares values. Use === for comparisons to avoid surprising type coercion.
    • Forgetting arrays start at zero. The first item is at index 0, not 1.
    • Declaring everything as let. Default to const so accidental reassignment becomes an obvious error.
    • Expecting console.log to change the page. It only prints to the developer console; updating the visible page needs the DOM.

    FAQ

    Is JavaScript the same as Java? No. Despite the similar name, they are entirely different languages with different uses. The naming is a historical accident.

    Do I need to install anything to start? No. Every browser includes a JavaScript engine and a console (open developer tools). You can experiment immediately.

    Keep learning

    Want to build for the web? Explore our courses in Jalgaon.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses
    Atul Kabra

    Founder, Infoplanet

    Atul Kabra founded Infoplanet in 2001 and has spent over two decades teaching programming — C, C++, Java, databases and more — to students across Maharashtra.

    Related guides