0% found this document useful (0 votes)
7 views3 pages

JavaScript Basics for Beginners

This document is a beginner's tutorial on JavaScript, covering essential concepts such as variables, data types, operators, conditions, loops, functions, arrays, objects, and DOM manipulation. Each section includes examples to illustrate how JavaScript can be used to make websites interactive and manage data. The tutorial aims to provide foundational knowledge for those new to JavaScript programming.

Uploaded by

Safvannk Manjeri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

JavaScript Basics for Beginners

This document is a beginner's tutorial on JavaScript, covering essential concepts such as variables, data types, operators, conditions, loops, functions, arrays, objects, and DOM manipulation. Each section includes examples to illustrate how JavaScript can be used to make websites interactive and manage data. The tutorial aims to provide foundational knowledge for those new to JavaScript programming.

Uploaded by

Safvannk Manjeri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Beginner Tutorial (With Examples)

1. What is JavaScript?
JavaScript makes websites interactive. Example:
<!DOCTYPE html>
<html>
<head>
<title>My First JS</title>
</head>
<body>
<h1>Hello JavaScript!</h1>
<button onclick="alert('Hello, welcome!')">Click Me</button>
</body>
</html>

2. Variables (Storing Data)


We use variables to store values.
<script>
let name = "John";
let age = 20;
let isStudent = true;
[Link](name);
</script>

3. Data Types
Strings, numbers, booleans, arrays, and objects.
<script>
let fruits = ["Apple", "Banana", "Mango"];
[Link](fruits[1]);
</script>

4. Operators
Operators perform calculations.
<script>
let x = 10, y = 3;
[Link](x + y);
[Link](x % y);
</script>

5. Conditions (if / else)


Conditions allow decision-making.
<script>
let age = 18;
if (age >= 18) {
[Link]("You are adult");
} else {
[Link]("You are minor");
}
</script>

6. Loops
Repeat actions with loops.
<script>
for (let i = 1; i <= 5; i++) {
[Link]("Number " + i);
}
</script>

7. Functions
Functions allow reusing code.
<script>
function greet(name) {
[Link]("Hello " + name);
}
greet("Ali");
greet("Sara");
</script>

8. Arrays
Arrays store multiple values.
<script>
let colors = ["Red", "Green", "Blue"];
[Link]("Yellow");
[Link](colors);
</script>

9. Objects
Objects store key-value pairs.
<script>
let person = { name: "Ayesha", age: 22, isStudent: false };
[Link]([Link]);
</script>

10. DOM Manipulation


JavaScript can change webpage content.
<!DOCTYPE html>
<html>
<body>
<h2 id="title">Old Text</h2>
<button onclick="changeText()">Change</button>
<script>
function changeText() {
[Link]("title").innerHTML = "New Text!";
}
</script>
</body>
</html>

Summary
✔ Variables ✔ Data Types ✔ Operators ✔ Conditions ✔ Loops ✔ Functions ✔ Arrays & Objects ✔
DOM basics

You might also like