meson

meson / gistfile1.txt

Last active 58 minutes ago

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