JavaScript Tutorial for Beginners

๐ŸŒ What is JavaScript?

JavaScript is a programming language used to make websites interactive. It works with HTML and CSS.

๐Ÿงฐ Tools You Need

๐Ÿฅ‡ Section 1: Hello, World!

Try this simple example:

<!DOCTYPE html>
<html>
<head>
  <title>My First JS</title>
</head>
<body>

<h1>Hello JavaScript</h1>

<script>
  alert("Hello, World!");
</script>

</body>
</html>

This code shows a popup alert that says Hello, World!.

๐Ÿฅˆ Section 2: Variables

Variables store data. Example:

let name = "Alice";
let age = 25;

console.log(name); // Alice
console.log(age);  // 25

Use let for variables, const for constants.

๐Ÿฅ‰ Section 3: Data Types

TypeExample
String"hello"
Number10, 3.14
Booleantrue, false
Array[1, 2, 3]
Object{ name: "Bob" }
nullnull
undefinedundefined

๐Ÿง  Section 4: Functions

function greet(name) {
  console.log("Hello, " + name + "!");
}

greet("Alice"); // Hello, Alice!

๐Ÿ” Section 5: Conditions and Loops

If-Else Example
let age = 18;

if (age >= 18) {
  console.log("You're an adult");
} else {
  console.log("You're a minor");
}
Loop Example
for (let i = 1; i <= 5; i++) {
  console.log("Number: " + i);
}

๐Ÿ“ฆ Section 6: Arrays and Objects

Arrays
let fruits = ["apple", "banana", "orange"];
console.log(fruits[0]); // apple
Objects
let person = {
  name: "Alice",
  age: 25
};

console.log(person.name); // Alice

๐Ÿงฑ Section 7: DOM Manipulation

Try this interactive example:

Hello

Code Example:

document.getElementById('btnClickMe').addEventListener('click', function () {
  document.getElementById('demo').innerHTML = 'You clicked the button!';
});
  

๐Ÿš€ What's Next?

๐Ÿงช Practice Sites