Printing Output with console.log
Introduction
Welcome to Writing and Running Your First JavaScript Programs! This is the very first lesson of the very first course in this path, so we are standing right at the starting line together. Whether we have never written a line of code before or are just brushing up on the basics, this is exactly the right place to begin.
By the end of this lesson, we will understand what a program actually is, we will have written a small program that greets the world and shows a number, and we will know how to run that program and see what it does. Let's begin from the very beginning.
What Is a Program?
A computer is a machine that follows instructions extremely well and extremely fast. There is a catch, though: computers do not understand human languages like English. They need their instructions written in a special, precise form called a programming language.
A programming language is a set of words and rules that lets us tell a computer exactly what to do, one step at a time. There are many such languages, and the one we are learning is called JavaScript. It runs in every web browser in the world and on countless servers, which makes it one of the most useful languages anyone can learn.
A few words we will use constantly:
- The instructions we write are called code.
- A file containing code is a program. Our programs will live in a file called
main.js, and the.jsending marks it as a JavaScript file. - When we ask the computer to follow those instructions, we say we run the program.
How Does JavaScript Run Our Code?
Deep down, a computer only understands a stream of very simple signals. We would never want to write instructions at that level by hand. Instead, a helper program reads our JavaScript and carries it out for us. In this course that helper is called Node.js, and it is already set up for us.
When we run a program, Node.js reads our file from top to bottom, one line at a time, and does what each line says before moving to the next. We simply write clear JavaScript, and Node.js handles the rest.
That single idea, top to bottom, one line at a time, is worth remembering. For the short, straight-line programs in this course, our lines run in exactly the order we write them. Later courses will teach us how to make a program choose between paths or repeat steps, but for now, top to bottom is all we need.
