|
| 1 | +--- |
| 2 | +sidebar_position: 1 |
| 3 | +title: "Hello JavaScript!" |
| 4 | +sidebar_label: Intro to JavaScript |
| 5 | +description: "The ultimate beginner's guide to starting your programming journey." |
| 6 | +--- |
| 7 | + |
| 8 | +Think of your favorite website. When you click a "Like" button and the heart turns red, or when you type in a search bar and suggestions pop up that is **JavaScript** in action. |
| 9 | + |
| 10 | +### The Big Three: A Simple Analogy |
| 11 | + |
| 12 | +If building a website is like building a house: |
| 13 | +1. **HTML** is the **Structure** (The walls, doors, and windows). |
| 14 | +2. **CSS** is the **Decoration** (The paint, wallpaper, and furniture). |
| 15 | +3. **JavaScript** is the **Electricity & Plumbing** (The lights that turn on when you flip a switch and the water that flows when you turn a tap). |
| 16 | + |
| 17 | +## What is JavaScript, Exactly? |
| 18 | + |
| 19 | +JavaScript is a **Programming Language**. It allows you to tell the browser (Chrome, Safari, Edge) to do specific tasks. It is the most popular language in the world because it is the only language that runs natively in every web browser. |
| 20 | + |
| 21 | +### What can you do with it? |
| 22 | + |
| 23 | +* **Make things move:** Create animations or sliders. |
| 24 | +* **Handle Data:** Calculate a math problem or process a form. |
| 25 | +* **Update Content:** Change text or images without refreshing the page. |
| 26 | +* **Listen:** "Wait" for the user to click, scroll, or type. |
| 27 | + |
| 28 | +## Where Do We Write JavaScript? |
| 29 | + |
| 30 | +You don't need fancy software to start. You just need a text editor and a browser. There are three ways to add JS to your site: |
| 31 | + |
| 32 | +### 1. The Console (The Secret Playground) |
| 33 | + |
| 34 | +Every browser has a hidden "Console" for developers to test code. |
| 35 | +* **Try it:** Right-click this page -> **Inspect** -> Click the **Console** tab. |
| 36 | +* Type `alert("Hello World");` and hit Enter. |
| 37 | + |
| 38 | +### 2. Internal (The Script Tag) |
| 39 | + |
| 40 | +You can write code directly inside your HTML file using the `<script>` tag. |
| 41 | + |
| 42 | +```html |
| 43 | +<script> |
| 44 | + console.log("This code runs inside the HTML file!"); |
| 45 | +</script> |
| 46 | +``` |
| 47 | + |
| 48 | +### 3. External (The Professional Way) |
| 49 | + |
| 50 | +Just like CSS, we keep our JavaScript in its own file (e.g., `script.js`). This keeps our project clean. |
| 51 | + |
| 52 | +> Create a file named `script.js` and link it at the very bottom of your HTML, just before the closing `</body>` tag. |
| 53 | +
|
| 54 | +**In your HTML (at the very bottom of the body):** |
| 55 | + |
| 56 | +```html title="index.html" |
| 57 | +<body> |
| 58 | + <h1>Welcome to JS!</h1> |
| 59 | + |
| 60 | + <script src="script.js"></script> |
| 61 | +</body> |
| 62 | +``` |
| 63 | + |
| 64 | +## Your First Tool: The Console |
| 65 | + |
| 66 | +Before we build complex apps, we need a way to "talk" to the computer. We use the **Console**. Think of it as a private chat room between you and your code. |
| 67 | + |
| 68 | +<LiteYouTubeEmbed |
| 69 | + id="BMFbW9giTuw" |
| 70 | + params="autoplay=1&autohide=1&showinfo=0&rel=0" |
| 71 | + title="How To Run JavaScript In Google Chrome | Chrome Developer Tools" |
| 72 | + poster="maxresdefault" |
| 73 | + webp |
| 74 | +/> |
| 75 | + |
| 76 | +### Try This Right Now: |
| 77 | + |
| 78 | +1. Open any website (like https://www.google.com). |
| 79 | +2. Right-click and select **Inspect**. |
| 80 | +3. Click the **Console** tab at the top. |
| 81 | +4. Type this exactly and hit Enter: `alert("I am a JavaScript Developer!");` |
| 82 | + |
| 83 | +**What happened?** You just commanded the browser to take an action! |
| 84 | + |
| 85 | +## Interactive Playground |
| 86 | + |
| 87 | +Experiment with the code below. Try changing the text inside the quotes in the JS tab and see what happens when you click the button. |
| 88 | + |
| 89 | +<CodePenEmbed |
| 90 | +title="Your First JS Interaction" |
| 91 | +penId="RNGwVxm" |
| 92 | +/> |
| 93 | + |
| 94 | + |
| 95 | +## The "Logic" of Programming |
| 96 | + |
| 97 | +Learning JavaScript is like learning a **Recipe**. You have: |
| 98 | + |
| 99 | +1. **Storage:** Storing ingredients (Variables). |
| 100 | +2. **Instructions:** What to do with them (Functions). |
| 101 | +3. **Choices:** What to do if something happens (If/Else statements). |
| 102 | + |
| 103 | +## How JavaScript "Thinks" |
| 104 | + |
| 105 | +Programming is just giving a list of instructions to a computer. |
| 106 | + |
| 107 | +When you write JS, you are creating a "Recipe" for the browser to follow: |
| 108 | + |
| 109 | +1. **Find** the button on the page. |
| 110 | +2. **Listen** for a click. |
| 111 | +3. **Run** a specific action when that click happens. |
| 112 | + |
| 113 | +## Summary Checklist |
| 114 | + |
| 115 | +* [x] I understand that JS adds **interactivity** (behavior). |
| 116 | +* [x] I know that `script.js` is the standard file name for JS. |
| 117 | +* [x] I learned how to open the **Browser Console**. |
| 118 | +* [x] I triggered my first `alert()`. |
| 119 | +* [x] I know how to find the **Developer Console**. |
| 120 | +* [x] I know that `<script src="...">` links an external file. |
| 121 | +* [x] I successfully ran an `alert()` or `console.log()`. |
| 122 | + |
| 123 | +:::tip Did You Know? |
| 124 | +JavaScript was created in just **10 days** back in 1995! Today, it is the most popular programming language in the world, used by 98% of all websites. |
| 125 | +::: |
0 commit comments