×

Javascript

📌 Important Notice & Guidelines

  • Scholarship Rule: The percentage of marks you score in the test will be equal to the percentage of scholarship you receive.
  • Weekly Test: Tests will be conducted every Friday.
  • Result Update: Your marks/results will be updated on the WhatsApp Channel every Saturday.
  • New Batches: New batches will start every Monday.

1. Introduction to JavaScript

JavaScript is a lightweight, interpreted programming language. It is one of the core technologies of the World Wide Web, alongside HTML and CSS. It helps to make web pages interactive by handling events, validating forms, creating animations, and dynamically updating content. JavaScript runs inside the browser, but it can also run on servers using Node.js.

console.log('Hello World!');
       

Hello World!

2. Variables (var, let, const)

Variables are containers for storing data values. In JavaScript, variables can be declared in three ways: 1. var (function scoped, older way), 2. let (block scoped, modern way), 3. const (for constants which cannot be reassigned). Using meaningful variable names improves code readability.

var city = 'Delhi';
let age = 22;
const country = 'India';
console.log(city);
console.log(age);
console.log(country);

Delhi

22

India

3. Data Types

JavaScript supports various data types such as: 1. String - text values 2. Number - numeric values 3. Boolean - true/false 4. Object - collection of key-value pairs 5. Array - list of values 6. Null - empty value 7. Undefined - not assigned. Data types help in organizing and working with values correctly.

let name = 'Avinash';
let age = 25;
let isStudent = true;
let car = null;
let marks;
console.log(typeof name);
console.log(typeof age);
console.log(typeof isStudent);
console.log(car);
console.log(marks);

string

number

boolean

null

undefined

4. Operators

Operators are special symbols that perform operations on values and variables. Common operators include: - Arithmetic (+, -, *, /, %) - Assignment (=, +=, -=) - Comparison (==, ===, >, <) - Logical (&&, ||, !) Operators allow us to build expressions.

let a = 10, b = 3;
console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
console.log(a % b);
console.log(a > b);
console.log(a == 10 && b == 3);

13

7

30

3.333...

1

true

true

5. Functions

Functions are reusable blocks of code designed to perform a specific task. Functions can accept inputs (parameters) and return outputs. They help to avoid code repetition and improve maintainability.

function add(a, b){
return a + b;
}
let result = add(5, 7);
console.log(result);

12

6. Conditional Statements (if, else, switch)

Conditional statements in JavaScript are used to control the flow of a program. This means the code will only run if the condition is true. The most common statement is if, which checks a condition and runs its block if true. If the condition is false, it is skipped. The else block runs when the condition is false. We can also check multiple conditions using else if. The switch statement is useful when comparing multiple values against a single variable. These statements are very useful in real-world programs, such as creating login systems, showing error messages, or navigation based on user roles. Without them, decision-making is not possible.

let marks = 75;
if(marks >= 80){
  console.log("Grade A");
} else if(marks >= 60){
  console.log("Grade B");
} else {
  console.log("Grade C");
}
        

Grade B

7. Loops (for, while, do...while)

Loops in JavaScript are used to run the same code multiple times without rewriting it. The for loop is used when we know how many times the loop should run. It runs with initialization, condition, and increment. The while loop continues to run as long as the condition is true, which is useful when the number of iterations is not fixed. The do...while loop is similar to the while loop, but it runs the code at least once, regardless of the condition. Loops are important in real-life programming, such as printing numbers from 1 to 100, processing array elements, or creating animations. They make repetitive tasks easy and fast.

for(let i=1; i<=5; i++){
  console.log("Number:", i);
}
        

Number: 1
Number: 2
Number: 3
Number: 4
Number: 5

8. Arrays

An array in JavaScript is a special object that can store multiple values in a single variable. Arrays are useful when handling lists like names, marks, or fruits. Each element in an array has an index number starting from 0. We can access or modify elements using this index. JavaScript arrays have many built-in methods such as .push() (add an element), .pop() (remove last element), .shift() (remove first element), and .unshift() (add element at the start). Arrays are widely used in real-life applications like product lists in e-commerce or user posts in social media. They are a flexible and dynamic data structure and an important part of JavaScript.

let fruits = ["Apple", "Banana", "Mango"];
console.log(fruits[0]);
console.log(fruits.length);
        

Apple
3

9. Objects

Objects in JavaScript are an important data structure that store data in key-value pairs. In arrays, elements are stored using indices, but in objects, keys describe the values directly. Objects are powerful when representing real-world entities like a person, car, or product. For example, a person object can store name, age, and city. Values can be accessed using dot notation (object.key) or bracket notation (object["key"]). Objects are useful in JavaScript for creating APIs, managing settings, and storing structured information. They help represent and manipulate complex data.

let person = {
  name: "Avinash",
  age: 25,
  city: "Delhi"
};
console.log(person.name);
        

Avinash

10. Functions with Parameters & Return

Functions are reusable blocks of code that make programs modular and simple. Using parameters and return values makes functions even more powerful. Parameters provide input to the function, and the return statement can send a value back. This makes the code flexible and reduces repetition. For example, a multiplication function can take two parameters and return their product. In real-world programming, functions are used for calculations, form validation, and data processing. They make programs more reusable and maintainable.

function multiply(x, y){
  return x * y;
}
console.log(multiply(4, 6));
        

24

11. String Methods

JavaScript provides many built-in methods for strings that help in manipulating text. For example, length gives the size of the string, toUpperCase() and toLowerCase() convert the case, slice() extracts a substring, and replace() is used to replace text. String methods are very useful in real-world programming for input validation, formatting, and displaying data.

let text = "Hello World";
console.log(text.length);
console.log(text.toUpperCase());
console.log(text.slice(0,5));
console.log(text.replace("World","JavaScript"));
        

11
HELLO WORLD
Hello
Hello JavaScript

12. Date & Time

The Date object in JavaScript is used to handle the current date and time. We can retrieve the current day, month, year, hours, minutes, and seconds. This feature is important in real-world applications for timers, event scheduling, and logging.

let now = new Date();
console.log(now);
console.log("Year:", now.getFullYear());
console.log("Month:", now.getMonth() + 1);
console.log("Date:", now.getDate());
        

Wed Sep 12 2025 10:00:00 GMT+0530 (India Standard Time)
Year: 2025
Month: 9
Date: 12

13. DOM Manipulation

DOM (Document Object Model) in JavaScript is used to manipulate HTML elements. We can select elements, change their content, create new elements, and remove existing ones. This is essential for making web pages interactive and dynamic.

document.body.innerHTML += "<p>Hello DOM!</p>";
let heading = document.createElement("h2");
heading.innerText = "New Heading";
document.body.appendChild(heading);
        

Hello DOM!
New Heading

14. Event Handling

Events in JavaScript are used to detect and handle user actions such as clicks, mouse movements, and keyboard inputs. We can define functions for specific events using addEventListener(). This is very important in creating interactive web applications.

let button = document.createElement("button");
button.innerText = "Click Me";
document.body.appendChild(button);
button.addEventListener("click", function(){
  alert("Button Clicked!");
});
        

Button Clicked! (alert appears on clicking the button)

15. Local Storage

Local Storage in JavaScript is used to store data permanently in the browser. The data remains available even after the page is reloaded or the browser is closed. Local Storage stores data as key-value pairs and is useful for small settings, preferences, and temporary data.

localStorage.setItem("username", "Avinash");
console.log(localStorage.getItem("username"));
localStorage.removeItem("username");
        

Avinash

Best of Luck to All Students!

Give your best in the test, stay focused, and keep learning something new every day. Believe in yourself, and let each lesson make you stronger and smarter.

WhatsApp Chat