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

Navigating the Web: A Journey into the World of Web Development

 Introduction: In the age of the internet, web development stands as the architectural backbone that shapes our online experiences. It is the art and science of crafting the digital landscape we navigate daily, creating everything from informative blogs and interactive applications to e-commerce platforms and social media networks. At its core, web development involves the process of building, designing, and maintaining websites, transforming creative visions into functional and visually appealing online destinations. Developers, armed with a diverse set of skills, collaborate to bring websites to life, seamlessly blending aesthetics with functionality. Web development is a multifaceted discipline, encompassing both front-end and back-end development. Front-end developers focus on the user interface (UI) and user experience (UX), using languages like HTML, CSS, and JavaScript to ensure a website's visual appeal and interactivity. On the other hand, back-end developers delve into th...

Crafting User-Friendly Experiences: An Introduction to Responsive Web Design

  Introduction: Importance of Responsive Design:      Responsive design can help you solve a lot of problems for your website. It will make your site mobile-friendly, improve the way it looks on devices with both large and small screens, and increase the amount of time that visitors spend on your site. It can also help you improve your rankings in search engines. 1. User Experience (UX) Optimization:      Responsive Web Design (RWD) ensures a seamless and consistent user experience across diverse devices, from desktops to smartphones. Users can access and interact with content without disruptions, fostering a positive UX. 2. Mobile-First Approach:      Adopting a mobile-first strategy prioritizes design and functionality for mobile devices. This approach recognizes the increasing use of smartphones and ensures that the website is optimized for smaller screens. Designs are then progressively enhanced for larger screens. 3. Search Engine O...

Getting started with CSS frameworks, focusing on Bootstrap:

Introduction 1. Introduction to Popular CSS Frameworks: Bootstrap: Features: Responsive Grid System: A 12-column grid system that adapts to various screen sizes. Pre-styled Components: Buttons, forms, navigation bars, and more, ensuring a cohesive design. Utility Classes: Extensive utility classes for quick styling without custom CSS. How to Get Started: CDN:     ```html     <!-- Add this in the head of your HTML file -->     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">     ``` Installation via npm:     ```bash     npm install bootstrap     ``` Include in Your Project: Reference the Bootstrap CSS file in your HTML. 2. How to Use Bootstrap for Faster and More Consistent Development: Integration: HTML Structure:   ```html   <!DOCTY...