Skip to main content

 

JavaScript Full Guide 

1. What is JavaScript?

JavaScript (JS) is a programming language used to make websites interactive.

If a website is:

  • Just text → HTML
  • Styled → CSS
  • Interactive (clicks, animations, login, updates) → JavaScript

 Example:

  • Clicking a button
  • Showing popup messages
  • Validating login form
  • Updating content without refreshing page

JavaScript runs inside the browser (Chrome, Firefox, etc.).



2. How JavaScript Works

When a user opens a website:

  1. HTML loads (structure)
  2. CSS loads (design)
  3. JavaScript runs (logic & actions)

JavaScript is like the brain of the website

3. Where to Write JavaScript?

There are 3 ways:

1. Inside HTML file

<script>
console.log("Hello JavaScript");
</script>

2. External file (best practice)

<script src="script.js"></script>

3. Inline (not recommended)

<button onclick="alert('Hi')">Click</button>

4. Variables (Storing Data)

Variables are used to store values.

let name = "Abhi";
let age = 18;

console.log(name);
console.log(age);

Types of variables:

  • let → can change value
  • const → cannot change value
  • var → old (avoid using)

5. Data Types (Types of Values)

JavaScript supports:

1. String

let name = "Hello";

2. Number

let age = 20;

3. Boolean

let isStudent = true;

4. Array (list)

let marks = [80, 90, 85];

5. Object (grouped data)

let student = {
name: "Abhi",
age: 20
};

6. Operators (Math & Logic)

Arithmetic:

let a = 10;
let b = 5;

console.log(a + b); // 15
console.log(a - b); // 5
console.log(a * b); // 50
console.log(a / b); // 2

Comparison:

console.log(10 > 5); // true
console.log(10 == 10); // true

7. Conditions (Decision Making)

Used when we want to make decisions.

let age = 18;

if (age >= 18) {
console.log("You can vote");
} else {
console.log("Not eligible");
}

Think like: “If this happens → do this”

8. Loops (Repeat Work)

For loop:

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

Output: 1 2 3 4 5

9. Functions (Reusable Code)

Functions help avoid repeating code.

function greet() {
console.log("Hello Student!");
}

greet();
greet();

 You can call it anytime.

10. Arrays (Working with Lists)

let fruits = ["Apple", "Banana", "Mango"];

console.log(fruits[0]); // Apple

Useful methods:

fruits.push("Orange"); // add
fruits.pop(); // remove last

11. Objects (Real-life data)

let student = {
name: "Abhi",
age: 20,
course: "CSE"
};

console.log(student.name);

 Used in real applications like user profiles.

12. DOM (Most Important Concept)

DOM = Document Object Model
It means JavaScript can change HTML content.

Example:

<p id="text">Hello</p>
<button onclick="changeText()">Click</button>

<script>
function changeText() {
document.getElementById("text").innerHTML = "Text Changed!";
}
</script>

This is how websites become interactive.

13. Events (User Actions)

Events happen when user interacts.

Examples:

  • click
  • hover
  • input
  • submit
function show() {
alert("Button clicked!");
}

Comments

Popular posts from this blog

 Restaurant Reservation System(Mini Project) Using HTML,CSS and JavaScript Project Title: Restaurant Reservation System 🔍 Description: The Restaurant Reservation System is a web-based application designed to streamline the table booking process for restaurants. It enables customers to make reservations quickly and conveniently by filling out an online form with their personal details, preferred date, time, number of guests, and any special requests. The system performs smart validation to ensure that users cannot book for past dates or time slots that have already passed, especially on the current day. Upon successful booking, a confirmation message is displayed to the user. 🛠️ Technologies Used: HTML – for structuring the form elements and layout. CSS (Internal) – for styling the form, layout, and confirmation box. JavaScript (Internal) – for form validation, logic to block past bookings, and dynamic confirmation messages. 🎯 Features: User-friendly form...

Getting Started with CSS Frameworks: A Guide to Bootstrap

INTRODUCTON 1. Introduction to Popular CSS Frameworks: Bootstrap:      Widely embraced in the front-end development sphere, Bootstrap stands out with its responsive grid system, pre-styled components, and a rich set of utility classes. It streamlines development, ensuring a uniform user experience across diverse devices. Foundation:      Renowned for its mobile-first strategy and modular design, Foundation offers a flexible grid system and customizable UI components. Tailwind CSS:      Diverging from traditional frameworks, Tailwind CSS follows a utility-first approach. It provides low-level utility classes, allowing direct design implementation in your markup. 2. How to Use CSS Frameworks for Faster and More Consistent Development: Integration: Link the framework's stylesheet in your HTML file or utilize npm for installation. Import the required styles into your project. Grid System: Leverage the grid system for responsive layout design. Exa...

Creating a login page using HTML,CSS,JS

Creating Login/Signup form   A strong login and registration form is crucial for websites and applications in the rapidly evolving world of the internet. This tutorial will walk you through using HTML, CSS, and JavaScript to create a sleek and contemporary login and registration form. After completing this course, you'll be able to create a form for your website or app that is both functional and aesthetically pleasing. The majority of websites and applications use login forms. The user can access the website or web application they are browsing with the aid of the login form. Steps: Establishing the Project: Establish the project's initial file system and structure. Establishing the HTML Form: Establish the fundamental framework for the registration and login forms. Talk about styling your form with CSS to ensure that it looks good and functions properly across a range of devices. Adding Functionality with JavaScript: Investigate using JavaScript to give your form features and...