During this course, you will:
Live code examples are scattered throughout this text. These snippets of code can be edited and run from within the browser. Click and type within the box to edit, and press the “Run” button to see what they do.
console.log function (or method) prints its argument to the console, followed by a newline. We will be using it a lot.
There are two other useful functions that you might see often. The
alert function displays a text box with the specified message.
prompt function displays a box prompting the user for input.
alert(prompt("What is your name?"));
.js file, and link to the page using the
src attribute, such as
<script src="code.js"></script>. Note that in this case, the contents of the script tag should be empty.
The nice thing about interpreted languages is that they are designed to be run with a single pass through the source code, running each instruction step-by-step. That means that we can give the interpreter a single step and ask it to run it.
Try running some simple math expressions within the console, such as
1 + 2 or
Now try to run the hello world program in the console. It produces two lines of output. The first line is the greeting that we expect. The second line reads
console.log function, return an empty result called
Note that the console prints out the result of the expression, whereas the live code examples do not. We will be using
console.log to evaluate expressions in the live code examples, but you can omit