A program is a set of precise instructions that asks a computer to solve a problem. Computers do not directly understand natural language; even “calculate 1 + 2” must be written as executable steps.
A programming language lets us express those steps as source code. A JavaScript engine in a browser or Node.js parses and executes that code. Languages such as Python, C, C++, Java, and JavaScript use different syntax, but they share one goal: tell the computer exactly what to do.
What is a program?
Most programs combine four kinds of action:
- Input: receive data from a keyboard, file, or network.
- Processing: calculate, compare, transform, or store data.
- Output: display a result or send it somewhere else.
- Control flow: decide the order of steps, repetitions, and conditions.
You do not need to memorize every JavaScript rule at once. Begin with a program as a clear sequence of steps that the computer follows exactly.
Flowchart
A flowchart shows the order of execution before you write code. The diagram below sums the integers from 1 through 100. A diamond represents a decision: when the condition is true, the loop continues; when it is false, the program prints the result and ends.
The JavaScript code performs initialization, testing, accumulation, updating, and output in that order:
let i = 1;
let total = 0;
while (i <= 100) {
total = total + i;
i = i + 1;
}
console.log(total);Save the code as main.js. Run it in a browser console or with node main.js; it prints 5050.
KNOWLEDGE QUIZ
Your first JavaScript program
Hello World is usually the first program in a new language. It does one thing: prints a piece of text.
console.log("Hello World!");Output:
Hello World!console.log() writes the value inside its parentheses to the console. "Hello World!" is a string, so it is wrapped in quotes. JavaScript often allows the final semicolon to be omitted, but this course keeps it to make statement boundaries clear.
KNOWLEDGE QUIZ
Hello World in other languages
Different languages can perform the same output task, but their syntax and entry points differ. Compare the four examples below to recognize their shapes; you do not need to understand every line yet.
print("Hello World!")#include <stdio.h>
int main(void) {
printf("Hello World!\n");
return 0;
}#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}Python and JavaScript can place an output statement directly in the file. Complete C, C++, and Java examples explicitly declare an entry point. All five examples print the same line.
Comments
Comments are notes for people and are not executed. A single-line comment starts with //; a multi-line comment goes between /* and */.
console.log("Hello World!"); // print one line
/*
This is a
multi-line comment.
*/Use comments to explain why a choice was made instead of repeating what the code already says.
KNOWLEDGE QUIZ
Print a three-line learning card
Write a tiny runnable JavaScript program that prints three lines with console.log, and add one comment explaining the purpose of one line.
- Print a greeting on line 1, for example "Hello, Leaflet!".
- Print the course you are studying on line 2, for example "JavaScript Basics".
- Print one learning goal on line 3, for example "I want to write conditionals".
- Add one single-line comment that starts with // above any line.