| 1 | // 1. Variables and Data Types |
| 2 | const greeting = "Hello, JavaScript world!"; // String (cannot be reassigned) |
| 3 | let counter = 10; // Number (can be changed) |
| 4 | const isLearning = true; // Boolean |
| 5 | |
| 6 | console.log(greeting); |
| 7 | |
| 8 | // 2. A Simple Function |
| 9 | // This function takes a name as an input and returns a personalized message |
| 10 | function greetUser(userName) { |
| 11 | return `Welcome back, ${userName}!`; |
| 12 | } |
| 13 | |
| 14 | // Calling the function and saving the result |
| 15 | const userMessage = greetUser("Alex"); |
| 16 | console.log(userMessage); |
| 17 | |
| 18 | // 3. Arrays (Lists) and Loops |
| 19 | const programmingLanguages = ["JavaScript", "Python", "C++", "Java"]; |
| 20 | |
| 21 | console.log("Here are some popular languages:"); |
| 22 | // Loop through each item in the array |
| 23 | for (const language of programmingLanguages) { |
| 24 | console.log(`- ${language}`); |
| 25 | } |
| 26 | |
| 27 | // 4. Conditionals (If/Else Statement) |
| 28 | if (counter > 5) { |
| 29 | console.log("The counter is greater than 5."); |
| 30 | } else { |
| 31 | console.log("The counter is 5 or less."); |
| 32 | } |
| 33 |
meson / gistfile1.txt
Last active 58 minutes ago