Your First Code
Write your first program and learn the basics of JavaScript execution.
Next Step: Running CodeYour Journey Begins Here
Step 1: Create a File
Open your text editor and create a new file named distress-signal.js
.
// distress-signal.js
console.log("SOS - Help is on the way!");
Step 2: Run Your Code
Open your terminal at the file location and run:
node distress-signal.js
Understanding the Output
You should see this in your terminal:
SOS - Help is on the way!
Let's explore some basic JavaScript concepts:
Variables
let survivorCount = 42;
survivorCount = survivorCount + 3;
Conditionals
if (weather === "storm") {
console.log("Stay in the cave!");
} else {
console.log("Gather resources!");
}
Loops
for (let i = 0; i < 5; i++) {
console.log("Drill " + i);
}
Ready for More?
You've successfully sent your first code distress signal! Now it's time to learn how to run and test your code practically.
Start Running Code