Welcome to JavaScript
Explain where JavaScript runs, recognize the parts of a tiny program, and write your first console output.
By the end, you’ll be able to…
- Explain what JavaScript is and where it runs.
- Distinguish a browser host from a Node.js host.
- Recognize statements, comments, and case-sensitive identifiers.
- Write and run a first program with console.log.
01A language for interactive software
JavaScript is a programming language used to describe behavior: what should happen when a page loads, a button is clicked, or a server receives a request. The language itself is standardized as ECMAScript, while the engines that execute it are built by browser and runtime teams. You write source code as plain text; an engine reads that text and follows its instructions.
JavaScript is high-level and dynamically typed. You do not manage memory manually or declare a machine type for every value. That convenience makes it approachable, but the engine still follows precise rules. Spelling matters, punctuation matters, and every value has a type even when the source code does not name it. That is why the text 42 and the number 42 behave differently in a program.
02Two hosts, one language
A host is the environment that gives JavaScript a place to run. Every modern browser is a host. It supplies the page, the Document Object Model, and a developer console. Node.js is another host: it runs JavaScript outside a browser, which makes it useful for command-line tools, build scripts, and web servers.
The core language is the same in both places, but the surroundings differ. A browser script can read page elements; a Node.js script can read files and environment variables. console.log exists in both hosts, so it is a safe first tool. When an example depends on one host, the lesson will say which one.
03Statements, comments, and exact spelling
A program is a sequence of statements, and each statement asks for one action. Most statements end at a newline, and a semicolon can make that boundary explicit. Use semicolons consistently while learning. A comment begins with two slashes and runs to the end of the line; the engine ignores it. Comments should explain intent rather than repeat obvious syntax.
JavaScript is case-sensitive. console and Console are different names, and so are log and Log. Text inside a string keeps whatever case you type, but identifiers do not forgive a capital letter. Read an error message for the exact spelling. If console.log works and console.Log does not, the difference is the capital L, not a broken browser.
04Your first complete program
The program below contains three statements. Each call to console.log evaluates its arguments and writes them to the console, followed by a newline. Text in quotes is printed exactly; an expression such as 6 * 7 is calculated before it is printed. The output shows results, not the source code that produced them.
Run the program by pasting it into a browser console or by saving it as hello.js and running node hello.js. Predict the three lines before you run them, then change the name and the multiplication. Save and run again. A first program is not a ceremony; it is evidence that you can edit source code and observe the result.
The ideas worth keeping.
- JavaScript is standardized as ECMAScript and runs in hosts such as browsers and Node.js.
- A program is a sequence of statements; comments are ignored and identifiers are case-sensitive.
- console.log evaluates its arguments and prints the resulting values.
Make it yours.
Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.
Exercise 1: Write a three-line introduction
Write a program with three console.log calls. The first prints Name: Ada, the second prints Goal: learn JavaScript, and the third prints Weekly practice: followed by the result of 4 * 5. Pass the calculation as a separate argument in the third call.
Explore a worked solution
console.log("Name: Ada");console.log("Goal: learn JavaScript");console.log("Weekly practice:", 4 * 5);The first two calls receive a single string. The last call receives two arguments: a label and an expression. console.log evaluates 4 * 5 to 20 and separates the arguments with a space, producing Weekly practice: 20.
Exercise 2: Repair a broken greeting
The following attempt contains two mistakes: the call console.Log("Hello"); and a second call whose text starts with "Ready but never closes the quote. Write the corrected two-line program so it prints Hello and then Ready.
Explore a worked solution
console.log("Hello");console.log("Ready");JavaScript distinguishes console.Log from console.log, so the first call would fail. The second string is missing its closing quote, which prevents the file from parsing. Fixing the name and the quote produces two ordinary calls.
What stayed with you?
Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.
Exercise 1: Write a three-line introduction
Write a program with three console.log calls. The first prints Name: Ada, the second prints Goal: learn JavaScript, and the third prints Weekly practice: followed by the result of 4 * 5. Pass the calculation as a separate argument in the third call.
Name: Ada Goal: learn JavaScript Weekly practice: 20
Keep exploring.
The official references behind this lesson, when you want a second angle or the full details.
One lesson closer.
Reading is a start. Trying it yourself makes the connection.