๐ŸŒŸ JavaScript Introduction

JavaScript is a programming language used to make web pages interactive. It runs in the browser and can do things like:

  • Show/hide content
  • Create image sliders
  • Validate forms
  • Handle user events like clicks or key presses

๐Ÿ› ๏ธ Setting Up JavaScript

You can write JS directly in an HTML file:

htmlCopyEdit<!DOCTYPE html>
<html>
<head>
  <title>JS Intro</title>
</head>
<body>
  <h1>Hello, JavaScript!</h1>
  <script>
    alert('Welcome to JavaScript!');
  </script>
</body>
</html>

๐Ÿ“š JS Basics (With Examples)

1. โœ… Variables

Used to store data.

jsCopyEditlet name = "Alice";
const age = 25;
var city = "New York";

2. ๐Ÿ“ Data Types

jsCopyEditlet text = "Hello";      // String
let number = 100;        // Number
let isCool = true;       // Boolean
let nothing = null;      // Null
let something;           // Undefined
let items = [1, 2, 3];   // Array

3. ๐Ÿ” Functions

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

greet("Sam");

4. ๐Ÿ”„ Conditional Statements

jsCopyEditlet age = 20;

if (age >= 18) {
  console.log("You are an adult");
} else {
  console.log("You are a minor");
}

5. ๐Ÿ”ƒ Loops

jsCopyEditfor (let i = 1; i <= 5; i++) {
  console.log("Count: " + i);
}

6. ๐Ÿ“ฆ Objects

jsCopyEditlet person = {
  name: "John",
  age: 30,
  isStudent: false
};

console.log(person.name); // Output: John

๐Ÿ–ฑ๏ธ Interacting with the Browser (DOM)

Example: Changing content on click

htmlCopyEdit<p id="demo">Hello!</p>
<button onclick="changeText()">Click Me</button>

<script>
  function changeText() {
    document.getElementById("demo").innerHTML = "You clicked the button!";
  }
</script>

๐Ÿš€ Next Steps

  1. Practice: Build small things like a counter, a to-do list, or a quiz.
  2. Learn more:

Would you like me to turn this into a mini-course or build a beginner project (like a calculator or to-do list) with you step-by-step?

Leave a Reply

Your email address will not be published. Required fields are marked *